|
41 | 41 | import java.util.Set; |
42 | 42 | import java.util.stream.Collectors; |
43 | 43 |
|
| 44 | +import org.apache.logging.log4j.LogManager; |
| 45 | +import org.apache.logging.log4j.Logger; |
| 46 | + |
44 | 47 | import org.apache.pdfbox.cos.COSArray; |
45 | 48 | import org.apache.pdfbox.cos.COSBase; |
46 | 49 | import org.apache.pdfbox.cos.COSBoolean; |
|
84 | 87 | */ |
85 | 88 | public class COSWriter implements ICOSVisitor |
86 | 89 | { |
| 90 | + private static final Logger LOG = LogManager.getLogger(COSWriter.class); |
| 91 | + |
87 | 92 | /** |
88 | 93 | * The dictionary open token. |
89 | 94 | */ |
@@ -881,7 +886,8 @@ private void doWriteSignature() throws IOException |
881 | 886 | throw new IOException("Can't write new byteRange '" + byteRange + |
882 | 887 | "' not enough space: byteRange.length(): " + byteRange.length() + |
883 | 888 | ", byteRangeLength: " + byteRangeLength + |
884 | | - ", byteRangeOffset: " + byteRangeOffset); |
| 889 | + ", byteRangeOffset: " + byteRangeOffset + |
| 890 | + ", inLength: " + inLength); |
885 | 891 | } |
886 | 892 |
|
887 | 893 | // copy the new incremental data into a buffer (e.g. signature dict, trailer) |
@@ -1278,10 +1284,12 @@ private void detectPossibleSignature(COSDictionary obj) throws IOException |
1278 | 1284 | COSBase base3 = byteRange.get(3); |
1279 | 1285 | if (base2 instanceof COSInteger && base3 instanceof COSInteger) |
1280 | 1286 | { |
| 1287 | + // PDFBOX-5521 avoid hitting "old" signatures |
1281 | 1288 | long br2 = ((COSInteger) base2).longValue(); |
1282 | 1289 | long br3 = ((COSInteger) base3).longValue(); |
1283 | 1290 | if (br2 + br3 > incrementalInput.length()) |
1284 | 1291 | { |
| 1292 | + LOG.debug("reachedSignature at offset {}, byteRange: {}", getStandardOutput().getPos(), byteRange); |
1285 | 1293 | reachedSignature = true; |
1286 | 1294 | } |
1287 | 1295 | } |
|
0 commit comments