Skip to content

Commit 174ef57

Browse files
committed
PDFBOX-6071: check only index 2; add test; improve logging
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1928585 13f79535-47bb-0310-9956-ffa450edef68
1 parent 3b8fdec commit 174ef57

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,15 @@ void testPDFBox5521(boolean externallySign)
949949
final File file = new File("target/pdfs", "PDFBOX-5521-santander_freistellungsauftrag.pdf");
950950
signing.signDetached(file, new File(OUT_DIR + fileNameSigned));
951951
checkSignature(file, new File(OUT_DIR, fileNameSigned), false);
952+
953+
// PDFBOX-6071: file that has a /ByteRange longer than the file
954+
byte[] ba = Files.readAllBytes(file.toPath());
955+
ba[2434] = '9'; // change /ByteRange from [ 0 2490 14292 2385472] to [ 0 2490 14292 2985472]
956+
final File file2 = new File("target/pdfs", "PDFBOX-6071-santander_freistellungsauftrag.pdf");
957+
Files.write(file2.toPath(), ba);
958+
final String fileNameSigned2 = getOutputFileName("PDFBOX-6071-santander_freistellungsauftrag.pdf_signed{0}.pdf", externallySign);
959+
signing.signDetached(file2, new File(OUT_DIR + fileNameSigned2));
960+
checkSignature(file2, new File(OUT_DIR, fileNameSigned2), false);
952961
}
953962

954963
private void checkLTV(File outFile)

pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,15 +1281,14 @@ private void detectPossibleSignature(COSDictionary obj) throws IOException
12811281
if (byteRange != null && byteRange.size() == 4)
12821282
{
12831283
COSBase base2 = byteRange.get(2);
1284-
COSBase base3 = byteRange.get(3);
1285-
if (base2 instanceof COSInteger && base3 instanceof COSInteger)
1284+
if (base2 instanceof COSInteger)
12861285
{
12871286
// PDFBOX-5521 avoid hitting "old" signatures
12881287
long br2 = ((COSInteger) base2).longValue();
1289-
long br3 = ((COSInteger) base3).longValue();
1290-
if (br2 + br3 > incrementalInput.length())
1288+
if (br2 > incrementalInput.length())
12911289
{
1292-
LOG.debug("reachedSignature at offset {}, byteRange: {}", getStandardOutput().getPos(), byteRange);
1290+
LOG.debug("reachedSignature at offset {}, byteRange: {}, input length: {}",
1291+
getStandardOutput().getPos(), byteRange, incrementalInput.length());
12931292
reachedSignature = true;
12941293
}
12951294
}

0 commit comments

Comments
 (0)