From fc8f93053d4d11c07fe942a9baa9e23b98d80369 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sun, 25 Apr 2010 14:55:36 +0000 Subject: don't place restrictions on length of /ID strings git-svn-id: svn+q:///qpdf/trunk@961 71b93d88-0707-0410-a8cf-f5a4172ac649 --- libqpdf/QPDF_encryption.cc | 11 +----- qpdf/qtest/qpdf.test | 20 +++++++++- qpdf/qtest/qpdf/long-id-check.out | 17 ++++++++ qpdf/qtest/qpdf/long-id.pdf | 80 ++++++++++++++++++++++++++++++++++++++ qpdf/qtest/qpdf/short-id-check.out | 17 ++++++++ qpdf/qtest/qpdf/short-id.pdf | 80 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 214 insertions(+), 11 deletions(-) create mode 100644 qpdf/qtest/qpdf/long-id-check.out create mode 100644 qpdf/qtest/qpdf/long-id.pdf create mode 100644 qpdf/qtest/qpdf/short-id-check.out create mode 100644 qpdf/qtest/qpdf/short-id.pdf diff --git a/libqpdf/QPDF_encryption.cc b/libqpdf/QPDF_encryption.cc index d6b0ae23..8ac0ec90 100644 --- a/libqpdf/QPDF_encryption.cc +++ b/libqpdf/QPDF_encryption.cc @@ -24,7 +24,6 @@ static char const padding_string[] = { }; static unsigned int const O_key_bytes = sizeof(MD5::Digest); -static unsigned int const id_bytes = 16; static unsigned int const key_bytes = 32; void @@ -145,7 +144,7 @@ QPDF::compute_encryption_key( pbytes[2] = (char) ((data.P >> 16) & 0xff); pbytes[3] = (char) ((data.P >> 24) & 0xff); md5.encodeDataIncrementally(pbytes, 4); - md5.encodeDataIncrementally(data.id1.c_str(), id_bytes); + md5.encodeDataIncrementally(data.id1.c_str(), data.id1.length()); if ((data.R >= 4) && (! data.encrypt_metadata)) { char bytes[4]; @@ -343,14 +342,6 @@ QPDF::initializeEncryption() } std::string id1 = id_obj.getArrayItem(0).getStringValue(); - if (id1.length() != id_bytes) - { - throw QPDFExc(qpdf_e_damaged_pdf, this->file.getName(), - "trailer", this->file.getLastOffset(), - "first /ID string in trailer dictionary has " - "incorrect length"); - } - QPDFObjectHandle encryption_dict = this->trailer.getKey("/Encrypt"); if (! encryption_dict.isDictionary()) { diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test index 535d19d6..04128f86 100644 --- a/qpdf/qtest/qpdf.test +++ b/qpdf/qtest/qpdf.test @@ -77,7 +77,7 @@ flush_tiff_cache(); show_ntests(); # ---------- $td->notify("--- Miscellaneous Tests ---"); -$n_tests += 18; +$n_tests += 22; $td->runtest("qpdf version", {$td->COMMAND => "qpdf --version"}, @@ -134,6 +134,24 @@ $td->runtest("check output", {$td->FILE => "a.qdf"}, {$td->FILE => "unreferenced-indirect-scalar.out"}); +# Encrypt files whose /ID strings are other than 32 bytes long (bug +# 2991412). +foreach my $file (qw(short-id long-id)) +{ + $td->runtest("encrypt $file.pdf", + {$td->COMMAND => + "qpdf --encrypt '' pass 40 -- $file.pdf a.pdf"}, + {$td->STRING => "", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + + $td->runtest("check $file.pdf", + {$td->COMMAND => "qpdf --check a.pdf"}, + {$td->FILE => "$file-check.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +} + # Min/Force version $td->runtest("set min version", {$td->COMMAND => "qpdf --min-version=1.6 good1.pdf a.pdf"}, diff --git a/qpdf/qtest/qpdf/long-id-check.out b/qpdf/qtest/qpdf/long-id-check.out new file mode 100644 index 00000000..e2ffcef6 --- /dev/null +++ b/qpdf/qtest/qpdf/long-id-check.out @@ -0,0 +1,17 @@ +checking a.pdf +PDF Version: 1.3 +R = 2 +P = -4 +User password = +extract for accessibility: allowed +extract for any purpose: allowed +print low resolution: allowed +print high resolution: allowed +modify document assembly: allowed +modify forms: allowed +modify annotations: allowed +modify other: allowed +modify anything: allowed +File is not linearized +No syntax or stream encoding errors found; the file may still contain +errors that qpdf cannot detect diff --git a/qpdf/qtest/qpdf/long-id.pdf b/qpdf/qtest/qpdf/long-id.pdf new file mode 100644 index 00000000..9c575689 --- /dev/null +++ b/qpdf/qtest/qpdf/long-id.pdf @@ -0,0 +1,80 @@ +%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 + /ID [<443A32303130303432333131333433382B303227303027> <443A32303130303432333131333433382B303227303027>] +>> +startxref +556 +%%EOF diff --git a/qpdf/qtest/qpdf/short-id-check.out b/qpdf/qtest/qpdf/short-id-check.out new file mode 100644 index 00000000..e2ffcef6 --- /dev/null +++ b/qpdf/qtest/qpdf/short-id-check.out @@ -0,0 +1,17 @@ +checking a.pdf +PDF Version: 1.3 +R = 2 +P = -4 +User password = +extract for accessibility: allowed +extract for any purpose: allowed +print low resolution: allowed +print high resolution: allowed +modify document assembly: allowed +modify forms: allowed +modify annotations: allowed +modify other: allowed +modify anything: allowed +File is not linearized +No syntax or stream encoding errors found; the file may still contain +errors that qpdf cannot detect diff --git a/qpdf/qtest/qpdf/short-id.pdf b/qpdf/qtest/qpdf/short-id.pdf new file mode 100644 index 00000000..e068f846 --- /dev/null +++ b/qpdf/qtest/qpdf/short-id.pdf @@ -0,0 +1,80 @@ +%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 + /ID [<443A32303130303432333131> <443A32303130303432333131>] +>> +startxref +556 +%%EOF -- cgit v1.2.3-54-g00ecf