Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/org/verapdf/as/ASAtom.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ public class ASAtom implements Comparable<ASAtom> {
public static final ASAtom FDF = new ASAtom("FDF");
public static final ASAtom FF = new ASAtom("Ff");
public static final ASAtom FIELDS = new ASAtom("Fields");
public static final ASAtom FIGURE = new ASAtom("Figure");
public static final ASAtom FILE_ATTACHMENT = new ASAtom("FileAttachment");
public static final ASAtom FILESPEC = new ASAtom("Filespec");
public static final ASAtom FILTER = new ASAtom("Filter");
Expand All @@ -288,6 +289,7 @@ public class ASAtom implements Comparable<ASAtom> {
public static final ASAtom FONT_WEIGHT = new ASAtom("FontWeight");
public static final ASAtom FORM = new ASAtom("Form");
public static final ASAtom FORMTYPE = new ASAtom("FormType");
public static final ASAtom FORMULA = new ASAtom("Formula");
public static final ASAtom FREE_TEXT = new ASAtom("FreeText");
public static final ASAtom FRM = new ASAtom("FRM");
public static final ASAtom FS = new ASAtom("FS");
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/verapdf/pd/PDAnnotation.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,14 @@ public PD3DStream get3DD() {
}
return null;
}

public static Boolean isOutsideCropBox(PDPage page, PDAnnotation annotation) {
double[] cropBox = page.getCropBox();
double[] rectangle = annotation.getRect();
if (rectangle != null && rectangle.length >= 4) {
return cropBox[1] >= rectangle[3] || cropBox[0] >= rectangle[2]
|| cropBox[3] <= rectangle[1] || cropBox[2] <= rectangle[0];
}
return null;
}
Comment on lines +284 to +292
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Missing null/length check for cropBox will cause NullPointerException.

The method guards against a null or short rectangle array but performs no such check on cropBox. Per the PDPage.getCropBox() implementation (lines 112-119), when there is no /CropBox entry it falls back to getMediaBox(), which can return null. Accessing cropBox[0]cropBox[3] on a null reference will throw an NPE.

🐛 Proposed fix to add null/length guard for cropBox
     public static Boolean isOutsideCropBox(PDPage page, PDAnnotation annotation) {
         double[] cropBox = page.getCropBox();
         double[] rectangle = annotation.getRect();
-        if (rectangle != null && rectangle.length >= 4) {
+        if (cropBox != null && cropBox.length >= 4 && rectangle != null && rectangle.length >= 4) {
             return cropBox[1] >= rectangle[3] || cropBox[0] >= rectangle[2]
                     || cropBox[3] <= rectangle[1] || cropBox[2] <= rectangle[0];
         }
         return null;
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public static Boolean isOutsideCropBox(PDPage page, PDAnnotation annotation) {
double[] cropBox = page.getCropBox();
double[] rectangle = annotation.getRect();
if (rectangle != null && rectangle.length >= 4) {
return cropBox[1] >= rectangle[3] || cropBox[0] >= rectangle[2]
|| cropBox[3] <= rectangle[1] || cropBox[2] <= rectangle[0];
}
return null;
}
public static Boolean isOutsideCropBox(PDPage page, PDAnnotation annotation) {
double[] cropBox = page.getCropBox();
double[] rectangle = annotation.getRect();
if (cropBox != null && cropBox.length >= 4 && rectangle != null && rectangle.length >= 4) {
return cropBox[1] >= rectangle[3] || cropBox[0] >= rectangle[2]
|| cropBox[3] <= rectangle[1] || cropBox[2] <= rectangle[0];
}
return null;
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/org/verapdf/pd/PDAnnotation.java` around lines 284 - 292, The
method PDAnnotation.isOutsideCropBox currently checks rectangle for null/length
but not cropBox; add a null and length guard for the cropBox returned by
PDPage.getCropBox() (similar to rectangle) before indexing cropBox[0]..[3], and
return null if cropBox is null or has length < 4; update the conditional that
computes the boolean to only run when both cropBox and rectangle are non-null
and length >= 4 (method names: isOutsideCropBox, PDPage.getCropBox, local
variables: cropBox, rectangle).

}
Loading