From d54bd7b2658ae7cdef1276abe735613b1397a3bf Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sun, 7 Jan 2024 15:21:42 -0500 Subject: Add failing tests to illustrate qpdf's generation bug --- qpdf/qtest/incremental.test | 49 +++++++++++ qpdf/qtest/qpdf/incremental-1-out.qdf | 109 +++++++++++++++++++++++++ qpdf/qtest/qpdf/incremental-1-xref.out | 7 ++ qpdf/qtest/qpdf/incremental-1.pdf | 145 +++++++++++++++++++++++++++++++++ qpdf/qtest/qpdf/incremental-2-xref.out | 7 ++ qpdf/qtest/qpdf/incremental-2.pdf | 130 +++++++++++++++++++++++++++++ 6 files changed, 447 insertions(+) create mode 100644 qpdf/qtest/incremental.test create mode 100644 qpdf/qtest/qpdf/incremental-1-out.qdf create mode 100644 qpdf/qtest/qpdf/incremental-1-xref.out create mode 100644 qpdf/qtest/qpdf/incremental-1.pdf create mode 100644 qpdf/qtest/qpdf/incremental-2-xref.out create mode 100644 qpdf/qtest/qpdf/incremental-2.pdf diff --git a/qpdf/qtest/incremental.test b/qpdf/qtest/incremental.test new file mode 100644 index 00000000..db2a546d --- /dev/null +++ b/qpdf/qtest/incremental.test @@ -0,0 +1,49 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('incremental'); + +my $n_tests = 6; + +# Since the beginning but discovered at the time of releasing 11.8.0: +# qpdf doesn't delete earlier generations of an object when they are +# reused. +$td->runtest("handle delete and reuse", + {$td->COMMAND => "qpdf --qdf --static-id incremental-1.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "incremental-1-out.qdf"}, + $td->NORMALIZE_NEWLINES | $td->EXPECT_FAILURE); +$td->runtest("check xref", + {$td->COMMAND => "qpdf --show-xref incremental-1.pdf"}, + {$td->FILE => "incremental-1-xref.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES | $td->EXPECT_FAILURE); +$td->runtest("handle delete and reuse", + {$td->COMMAND => "qpdf --qdf --static-id incremental-2.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + # intentionally comparing incremental-2 with incremental-1-out + {$td->FILE => "incremental-1-out.qdf"}, + $td->NORMALIZE_NEWLINES | $td->EXPECT_FAILURE); +$td->runtest("check xref", + {$td->COMMAND => "qpdf --show-xref incremental-1.pdf"}, + {$td->FILE => "incremental-2-xref.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES | $td->EXPECT_FAILURE); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/qpdf/incremental-1-out.qdf b/qpdf/qtest/qpdf/incremental-1-out.qdf new file mode 100644 index 00000000..eaf021c3 --- /dev/null +++ b/qpdf/qtest/qpdf/incremental-1-out.qdf @@ -0,0 +1,109 @@ +%PDF-1.3 +%¿÷¢þ +%QDF-1.0 + +%% Original object ID: 1 0 +1 0 obj +<< + /Pages 2 0 R + /Type /Catalog +>> +endobj + +%% Original object ID: 2 0 +2 0 obj +<< + /Count 1 + /Kids [ + 3 0 R + ] + /Type /Pages +>> +endobj + +%% Page 1 +%% Original object ID: 3 0 +3 0 obj +<< + /Contents 4 0 R + /MediaBox [ + 0 + 0 + 612 + 792 + ] + /Parent 2 0 R + /Resources << + /Font << + /F1 5 0 R + >> + /ProcSet 6 0 R + >> + /Type /Page +>> +endobj + +%% Original object ID: 4 1 +4 0 obj +[ + 7 0 R +] +endobj + +%% Original object ID: 6 0 +5 0 obj +<< + /BaseFont /Helvetica + /Encoding /WinAnsiEncoding + /Name /F1 + /Subtype /Type1 + /Type /Font +>> +endobj + +%% Original object ID: 5 0 +6 0 obj +[ + /PDF + /Text +] +endobj + +%% Contents for page 1 +%% Original object ID: 7 0 +7 0 obj +<< + /Length 8 0 R +>> +stream +BT + /F1 24 Tf + 72 720 Td + (Salad) Tj +ET +endstream +endobj + +8 0 obj +43 +endobj + +xref +0 9 +0000000000 65535 f +0000000052 00000 n +0000000133 00000 n +0000000242 00000 n +0000000461 00000 n +0000000516 00000 n +0000000661 00000 n +0000000746 00000 n +0000000844 00000 n +trailer << + /Root 1 0 R + /Size 9 + /ID [<31415926535897932384626433832795><31415926535897932384626433832795>] +>> +startxref +863 +%%EOF diff --git a/qpdf/qtest/qpdf/incremental-1-xref.out b/qpdf/qtest/qpdf/incremental-1-xref.out new file mode 100644 index 00000000..43f4fddd --- /dev/null +++ b/qpdf/qtest/qpdf/incremental-1-xref.out @@ -0,0 +1,7 @@ +1/0: uncompressed; offset = 9 +2/0: uncompressed; offset = 63 +3/0: uncompressed; offset = 1069 +4/1: uncompressed; offset = 948 +5/0: uncompressed; offset = 403 +6/0: uncompressed; offset = 438 +7/0: uncompressed; offset = 974 diff --git a/qpdf/qtest/qpdf/incremental-1.pdf b/qpdf/qtest/qpdf/incremental-1.pdf new file mode 100644 index 00000000..eed2357f --- /dev/null +++ b/qpdf/qtest/qpdf/incremental-1.pdf @@ -0,0 +1,145 @@ +%PDF-1.3 +1 0 obj +<< + /Type /Catalog + /Pages 2 0 R +>> +endobj + +2 0 obj +<< + /Type /Pages + /Kids [ + 3 0 R + ] + /Count 1 +>> +endobj + +3 0 obj +<< + /Type /Page + /Parent 2 0 R + /MediaBox [0 0 612 792] + /Contents 4 0 R + /Resources << + /ProcSet 5 0 R + /Font << + /F1 6 0 R + >> + >> +>> +endobj + +4 0 obj +<< + /Length 44 +>> +stream +BT + /F1 24 Tf + 72 720 Td + (Potato) Tj +ET +endstream +endobj + +5 0 obj +[ + /PDF + /Text +] +endobj + +6 0 obj +<< + /Type /Font + /Subtype /Type1 + /Name /F1 + /BaseFont /Helvetica + /Encoding /WinAnsiEncoding +>> +endobj + +xref +0 7 +0000000000 65535 f +0000000009 00000 n +0000000063 00000 n +0000000135 00000 n +0000000307 00000 n +0000000403 00000 n +0000000438 00000 n +trailer << + /Size 7 + /Root 1 0 R +>> +startxref +556 +%%EOF + +% Delete object 4 and increment generation +xref +0 1 +0000000004 65535 f +4 1 +0000000000 00001 f +trailer << + /Size 7 + /Root 1 0 R + /Prev 556 +>> +startxref +807 +%%EOF + +% Reuse object 4 +4 1 obj +[ 7 0 R ] +endobj + +7 0 obj +<< + /Length 43 +>> +stream +BT + /F1 24 Tf + 72 720 Td + (Salad) Tj +ET +endstream +endobj + +3 0 obj +<< + /Type /Page + /Parent 2 0 R + /MediaBox [0 0 612 792] + /Contents 4 1 R + /Resources << + /ProcSet 5 0 R + /Font << + /F1 6 0 R + >> + >> +>> +endobj + +xref +0 1 +0000000000 65535 f +3 2 +0000001069 00000 n +0000000948 00001 n +7 1 +0000000974 00000 n +trailer << + /Size 8 + /Root 1 0 R + /Prev 807 + /Gone 4 0 R +>> +startxref +1241 +%%EOF diff --git a/qpdf/qtest/qpdf/incremental-2-xref.out b/qpdf/qtest/qpdf/incremental-2-xref.out new file mode 100644 index 00000000..6ff3fdee --- /dev/null +++ b/qpdf/qtest/qpdf/incremental-2-xref.out @@ -0,0 +1,7 @@ +1/0: uncompressed; offset = 9 +2/0: uncompressed; offset = 63 +3/0: uncompressed; offset = 1069 +4/0: uncompressed; offset = 307 +5/0: uncompressed; offset = 403 +6/0: uncompressed; offset = 438 +7/0: uncompressed; offset = 974 diff --git a/qpdf/qtest/qpdf/incremental-2.pdf b/qpdf/qtest/qpdf/incremental-2.pdf new file mode 100644 index 00000000..1759d86e --- /dev/null +++ b/qpdf/qtest/qpdf/incremental-2.pdf @@ -0,0 +1,130 @@ +%PDF-1.3 +1 0 obj +<< + /Type /Catalog + /Pages 2 0 R +>> +endobj + +2 0 obj +<< + /Type /Pages + /Kids [ + 3 0 R + ] + /Count 1 +>> +endobj + +3 0 obj +<< + /Type /Page + /Parent 2 0 R + /MediaBox [0 0 612 792] + /Contents 4 0 R + /Resources << + /ProcSet 5 0 R + /Font << + /F1 6 0 R + >> + >> +>> +endobj + +4 0 obj +<< + /Length 44 +>> +stream +BT + /F1 24 Tf + 72 720 Td + (Potato) Tj +ET +endstream +endobj + +5 0 obj +[ + /PDF + /Text +] +endobj + +6 0 obj +<< + /Type /Font + /Subtype /Type1 + /Name /F1 + /BaseFont /Helvetica + /Encoding /WinAnsiEncoding +>> +endobj + +xref +0 7 +0000000000 65535 f +0000000009 00000 n +0000000063 00000 n +0000000135 00000 n +0000000307 00000 n +0000000403 00000 n +0000000438 00000 n +trailer << + /Size 7 + /Root 1 0 R +>> +startxref +556 +%%EOF + +% Reuse object 4 without deleting first +4 1 obj +[ 7 0 R ] +endobj + +7 0 obj +<< + /Length 43 +>> +stream +BT + /F1 24 Tf + 72 720 Td + (Salad) Tj +ET +endstream +endobj + +3 0 obj +<< + /Type /Page + /Parent 2 0 R + /MediaBox [0 0 612 792] + /Contents 4 1 R + /Resources << + /ProcSet 5 0 R + /Font << + /F1 6 0 R + >> + >> +>> +endobj + +xref +0 1 +0000000000 65535 f +3 2 +0000000925 00000 n +0000000804 00001 n +7 1 +0000000830 00000 n +trailer << + /Size 8 + /Root 1 0 R + /Prev 556 + /Gone 4 0 R +>> +startxref +1097 +%%EOF -- cgit v1.2.3-54-g00ecf