Skip to content

Commit 3bea53f

Browse files
author
Samuel Huylebroeck
committed
Fix possible NPE
Possible NPE when handling a pdf with incorrect page rotation. Log and avoid using a default setting. SUP-1555, DEVSIX-832
1 parent c9fdc2d commit 3bea53f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

forms/src/main/java/com/itextpdf/forms/fields/PdfFormField.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ This file is part of the iText (R) project.
4343
*/
4444
package com.itextpdf.forms.fields;
4545

46+
import com.itextpdf.io.LogMessageConstant;
4647
import com.itextpdf.io.codec.Base64;
4748
import com.itextpdf.io.font.FontConstants;
4849
import com.itextpdf.io.font.PdfEncodings;
@@ -73,6 +74,8 @@ This file is part of the iText (R) project.
7374
import com.itextpdf.layout.property.Property;
7475
import com.itextpdf.layout.property.TextAlignment;
7576
import com.itextpdf.layout.property.VerticalAlignment;
77+
import org.slf4j.Logger;
78+
import org.slf4j.LoggerFactory;
7679

7780
import java.io.IOException;
7881
import java.nio.charset.StandardCharsets;
@@ -160,6 +163,7 @@ public class PdfFormField extends PdfObjectWrapper<PdfDictionary> {
160163
protected int rotation = 0;
161164
protected PdfFormXObject form;
162165
protected PdfAConformanceLevel pdfAConformanceLevel;
166+
protected Logger formFieldLogger;
163167

164168
protected static final String check = "0.8 0 0 0.8 0.3 0.5 cm 0 0 m\n" +
165169
"0.066 -0.026 l\n" +
@@ -235,6 +239,7 @@ public PdfFormField(PdfDictionary pdfObject) {
235239
super(pdfObject);
236240
ensureObjectIsAddedToDocument(pdfObject);
237241
setForbidRelease();
242+
formFieldLogger = LoggerFactory.getLogger(this.getClass());
238243
}
239244

240245
/**
@@ -1796,6 +1801,11 @@ public boolean regenerateField() {
17961801
//Copy Bounding box
17971802
bBox = new PdfArray(rect);
17981803
}
1804+
//Avoid NPE when handling corrupt pdfs
1805+
if(matrix == null){
1806+
formFieldLogger.error(LogMessageConstant.INCORRECT_PAGEROTATION);
1807+
matrix = new PdfArray(new double[]{1,0,0,1,0,0});
1808+
}
17991809

18001810
//Apply field rotation
18011811
float fieldRotation = 0;

io/src/main/java/com/itextpdf/io/LogMessageConstant.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,5 @@ public final class LogMessageConstant {
8989
public static final String WRITER_ENCRYPTION_IS_IGNORED_APPEND = "Writer encryption will be ignored, because append mode is used. Document will preserve the original encryption (or will stay unencrypted)";
9090
public static final String WRITER_ENCRYPTION_IS_IGNORED_PRESERVE = "Writer encryption will be ignored, because preservation of encryption is enabled. Document will preserve the original encryption (or will stay unencrypted)";
9191
public static final String XREF_ERROR = "Error occurred while reading cross reference table. Cross reference table will be rebuilt.";
92+
public static final String INCORRECT_PAGEROTATION = "Encounterd a page rotation that was not a multiple of 90°/ (Pi/2) when generating default appearances for form fields";
9293
}

0 commit comments

Comments
 (0)