Commit 718b14008ba9c1ad43ff2bfadfa70a60acdfdb82

Authored by m-holger
1 parent ff0affd8

Change QPDFWriter stream_decode_level default to qpdf_dl_generalized

Also, fix disabling of preserve_encryption to be ignore
stream_decode_level, but disable preserve_encryption if compress_streams is
false.

Fixes #1286
ChangeLog
@@ -3,6 +3,11 @@ @@ -3,6 +3,11 @@
3 * Add C API function qpdf_oh_free_buffer to release memory allocated 3 * Add C API function qpdf_oh_free_buffer to release memory allocated
4 by stream data functions. 4 by stream data functions.
5 5
  6 +2024-09-19 M Holger <m.holger@qpdf.org>
  7 +
  8 + * Bug fix: QPDFWriter stream DecodeLevel incorrectly defaulted to
  9 + none instead of generalied. Fixes #1286.
  10 +
6 2024-08-25 M Holger <m.holger@qpdf.org> 11 2024-08-25 M Holger <m.holger@qpdf.org>
7 12
8 * Add new command-line arguments --remove-metadata and --remove-info 13 * Add new command-line arguments --remove-metadata and --remove-info
libqpdf/QPDFWriter.cc
@@ -2126,7 +2126,7 @@ QPDFWriter::doWriteSetup() @@ -2126,7 +2126,7 @@ QPDFWriter::doWriteSetup()
2126 if (m->encrypted) { 2126 if (m->encrypted) {
2127 // Encryption has been explicitly set 2127 // Encryption has been explicitly set
2128 m->preserve_encryption = false; 2128 m->preserve_encryption = false;
2129 - } else if (m->normalize_content || m->stream_decode_level || m->pclm || m->qdf_mode) { 2129 + } else if (m->normalize_content || !m->compress_streams || m->pclm || m->qdf_mode) {
2130 // Encryption makes looking at contents pretty useless. If the user explicitly encrypted 2130 // Encryption makes looking at contents pretty useless. If the user explicitly encrypted
2131 // though, we still obey that. 2131 // though, we still obey that.
2132 m->preserve_encryption = false; 2132 m->preserve_encryption = false;
libqpdf/qpdf/QPDFWriter_private.hh
@@ -65,7 +65,7 @@ class QPDFWriter::Members @@ -65,7 +65,7 @@ class QPDFWriter::Members
65 bool normalize_content{false}; 65 bool normalize_content{false};
66 bool compress_streams{true}; 66 bool compress_streams{true};
67 bool compress_streams_set{false}; 67 bool compress_streams_set{false};
68 - qpdf_stream_decode_level_e stream_decode_level{qpdf_dl_none}; 68 + qpdf_stream_decode_level_e stream_decode_level{qpdf_dl_generalized};
69 bool stream_decode_level_set{false}; 69 bool stream_decode_level_set{false};
70 bool recompress_flate{false}; 70 bool recompress_flate{false};
71 bool qdf_mode{false}; 71 bool qdf_mode{false};
qpdf/qtest/encryption.test
@@ -723,7 +723,7 @@ $td-&gt;runtest(&quot;check file&#39;s validity&quot;, @@ -723,7 +723,7 @@ $td-&gt;runtest(&quot;check file&#39;s validity&quot;,
723 $td->runtest("handle missing/invalid Length", 723 $td->runtest("handle missing/invalid Length",
724 {$td->COMMAND => "qpdf --check bad-encryption-length.pdf"}, 724 {$td->COMMAND => "qpdf --check bad-encryption-length.pdf"},
725 {$td->FILE => "bad-encryption-length.out", 725 {$td->FILE => "bad-encryption-length.out",
726 - $td->EXIT_STATUS => 0}, 726 + $td->EXIT_STATUS => 3},
727 $td->NORMALIZE_NEWLINES); 727 $td->NORMALIZE_NEWLINES);
728 728
729 cleanup(); 729 cleanup();
qpdf/qtest/inline-images.test
@@ -56,7 +56,7 @@ $td-&gt;runtest(&quot;externalize damaged image&quot;, @@ -56,7 +56,7 @@ $td-&gt;runtest(&quot;externalize damaged image&quot;,
56 "qpdf --externalize-inline-images" . 56 "qpdf --externalize-inline-images" .
57 " --compress-streams=n --static-id" . 57 " --compress-streams=n --static-id" .
58 " damaged-inline-image.pdf a.pdf"}, 58 " damaged-inline-image.pdf a.pdf"},
59 - {$td->STRING => "", $td->EXIT_STATUS => 0}, 59 + {$td->FILE => "damaged-inline-image.out", $td->EXIT_STATUS => 3},
60 $td->NORMALIZE_NEWLINES); 60 $td->NORMALIZE_NEWLINES);
61 $td->runtest("check output", 61 $td->runtest("check output",
62 {$td->FILE => "a.pdf"}, 62 {$td->FILE => "a.pdf"},
qpdf/qtest/qpdf/bad-encryption-length.out
@@ -14,5 +14,5 @@ modify annotations: allowed @@ -14,5 +14,5 @@ modify annotations: allowed
14 modify other: allowed 14 modify other: allowed
15 modify anything: allowed 15 modify anything: allowed
16 File is not linearized 16 File is not linearized
17 -No syntax or stream encoding errors found; the file may still contain  
18 -errors that qpdf cannot detect 17 +WARNING: bad-encryption-length.pdf, object 7 0 at offset 531 -> dictionary key /Length: operation for integer attempted on object of type null: returning 0
  18 +qpdf: operation succeeded with warnings
qpdf/qtest/qpdf/damaged-inline-image.out 0 → 100644
  1 +WARNING: damaged-inline-image.pdf, stream object 8 0: error while getting stream data: stream inflate: inflate: data: invalid distance too far back
  2 +WARNING: damaged-inline-image.pdf, stream object 8 0: qpdf will attempt to write the damaged stream unchanged
  3 +qpdf: operation succeeded with warnings; resulting file may have some problems
qpdf/qtest/qpdf/fuzz-16214.out
@@ -6,6 +6,11 @@ WARNING: fuzz-16214.pdf (xref stream, offset 116): Cross-reference stream data h @@ -6,6 +6,11 @@ WARNING: fuzz-16214.pdf (xref stream, offset 116): Cross-reference stream data h
6 WARNING: fuzz-16214.pdf: reported number of objects (6) is not one plus the highest object number (35) 6 WARNING: fuzz-16214.pdf: reported number of objects (6) is not one plus the highest object number (35)
7 WARNING: fuzz-16214.pdf (object 14 0, offset 652): expected dictionary key but found non-name object; inserting key /QPDFFake1 7 WARNING: fuzz-16214.pdf (object 14 0, offset 652): expected dictionary key but found non-name object; inserting key /QPDFFake1
8 WARNING: fuzz-16214.pdf (object 14 0, offset 734): expected endobj 8 WARNING: fuzz-16214.pdf (object 14 0, offset 734): expected endobj
  9 +WARNING: fuzz-16214.pdf (object 15 0, offset 869): unknown token while reading object; treating as string
  10 +WARNING: fuzz-16214.pdf (object 15 0, offset 745): expected dictionary key but found non-name object; inserting key /QPDFFake1
  11 +WARNING: fuzz-16214.pdf (object 15 0, offset 894): expected endobj
  12 +WARNING: fuzz-16214.pdf, object 15 0 at offset 745: kid 0 (from 0) MediaBox is undefined; setting to letter / ANSI A
  13 +WARNING: fuzz-16214.pdf, object 15 0 at offset 745: /Type key should be /Page but is not; overriding
9 WARNING: fuzz-16214.pdf: file is damaged 14 WARNING: fuzz-16214.pdf: file is damaged
10 WARNING: fuzz-16214.pdf (object 1 0, offset 7189): expected n n obj 15 WARNING: fuzz-16214.pdf (object 1 0, offset 7189): expected n n obj
11 WARNING: fuzz-16214.pdf: Attempting to reconstruct cross-reference table 16 WARNING: fuzz-16214.pdf: Attempting to reconstruct cross-reference table
qpdf/qtest/qpdf/invalid-id-xref.out
@@ -15,4 +15,6 @@ modify annotations: allowed @@ -15,4 +15,6 @@ modify annotations: allowed
15 modify other: not allowed 15 modify other: not allowed
16 modify anything: not allowed 16 modify anything: not allowed
17 File is not linearized 17 File is not linearized
  18 +WARNING: invalid-id-xref.pdf, trailer at offset 910 -> dictionary key /ID: operation for array attempted on object of type null: returning null
  19 +WARNING: invalid-id-xref.pdf, trailer at offset 910 -> dictionary key /ID -> null returned from invalid array access: operation for string attempted on object of type null: returning empty string
18 qpdf: operation succeeded with warnings 20 qpdf: operation succeeded with warnings
qpdf/qtest/qpdf/job-json-input-file-password.pdf
1 Binary files a/qpdf/qtest/qpdf/job-json-input-file-password.pdf and b/qpdf/qtest/qpdf/job-json-input-file-password.pdf differ 1 Binary files a/qpdf/qtest/qpdf/job-json-input-file-password.pdf and b/qpdf/qtest/qpdf/job-json-input-file-password.pdf differ