@@ -324,17 +324,19 @@ protected void processAnnotation(PDAnnotation annotation, PDAppearanceStream app
324324 PDRectangle bbox = appearance .getBBox ();
325325 PDRectangle rect = annotation .getRectangle ();
326326
327- // zero-sized rectangles are not valid
327+ // PDFBOX-4783: zero-sized rectangles are not valid
328328 if (rect != null && rect .getWidth () > 0 && rect .getHeight () > 0 &&
329329 bbox != null && bbox .getWidth () > 0 && bbox .getHeight () > 0 )
330330 {
331- PDResources parent = pushResources (appearance );
332- Deque <PDGraphicsState > savedStack = saveGraphicsStack ();
333-
334331 Matrix matrix = appearance .getMatrix ();
335332
336333 // transformed appearance box fixme: may be an arbitrary shape
337334 Rectangle2D transformedBox = bbox .transform (matrix ).getBounds2D ();
335+ if (transformedBox .isEmpty ())
336+ {
337+ // PDFBOX-6095: zero-sized rectangles are not valid
338+ return ;
339+ }
338340
339341 // compute a matrix which scales and translates the transformed appearance box to align
340342 // with the edges of the annotation's rectangle
@@ -350,6 +352,9 @@ protected void processAnnotation(PDAnnotation annotation, PDAppearanceStream app
350352 // filled fields / annotations that have a matrix in the appearance stream, see PDFBOX-3083
351353 Matrix aa = Matrix .concatenate (a , matrix );
352354
355+ PDResources parent = pushResources (appearance );
356+ Deque <PDGraphicsState > savedStack = saveGraphicsStack ();
357+
353358 // make matrix AA the CTM
354359 getGraphicsState ().setCurrentTransformationMatrix (aa );
355360
0 commit comments