Skip to content

Commit baccac8

Browse files
Fix possible NPE in CompareTool#compareByCatalog in case pagesRef lists were not initialized during Catalog dictionaries comparison
1 parent 606e3e7 commit baccac8

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

kernel/src/main/java/com/itextpdf/kernel/utils/CompareTool.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,17 @@ public CompareResult compareByCatalog(PdfDocument outDocument, PdfDocument cmpDo
190190

191191
// Method compareDictionariesExtended eventually calls compareObjects method which doesn't compare page objects.
192192
// At least for now compare page dictionaries explicitly here like this.
193-
if (outPagesRef.size() != cmpPagesRef.size()) {
193+
if (cmpPagesRef == null || outPagesRef == null) {
194+
return compareResult;
195+
}
196+
197+
if (outPagesRef.size() != cmpPagesRef.size() && !compareResult.isMessageLimitReached()) {
194198
compareResult.addError(catalogPath, "Documents have different numbers of pages.");
195199
}
196200
for (int i = 0; i < Math.min(cmpPagesRef.size(), outPagesRef.size()); i++) {
201+
if (compareResult.isMessageLimitReached()) {
202+
break;
203+
}
197204
ObjectPath currentPath = new ObjectPath(cmpPagesRef.get(i), outPagesRef.get(i));
198205
PdfDictionary outPageDict = (PdfDictionary) outPagesRef.get(i).getRefersTo();
199206
PdfDictionary cmpPageDict = (PdfDictionary) cmpPagesRef.get(i).getRefersTo();

0 commit comments

Comments
 (0)