Commit 4977a7efa5d0b2d10f57af646e54a91d94d088ab
1 parent
22f7f459
Bug fix: getStreamData should on unfilterable stream (fixes #425)
Showing
6 changed files
with
48 additions
and
2 deletions
ChangeLog
| 1 | +2020-04-08 Jay Berkenbilt <ejb@ql.org> | ||
| 2 | + | ||
| 3 | + * Bug fix: qpdf 10.0.0 introduced a bug in which | ||
| 4 | + QPDFObjectHandle::getStreamData would return the raw data when | ||
| 5 | + called on an unfilterable stream instead of throwing an exception | ||
| 6 | + like it's supposed to. Fixes #425. | ||
| 7 | + | ||
| 1 | 2020-04-07 Jay Berkenbilt <ejb@ql.org> | 8 | 2020-04-07 Jay Berkenbilt <ejb@ql.org> |
| 2 | 9 | ||
| 3 | * Improve pdf-invert-images example to show a pattern of copying | 10 | * Improve pdf-invert-images example to show a pattern of copying |
libqpdf/QPDF_Stream.cc
| @@ -163,7 +163,9 @@ PointerHolder<Buffer> | @@ -163,7 +163,9 @@ PointerHolder<Buffer> | ||
| 163 | QPDF_Stream::getStreamData(qpdf_stream_decode_level_e decode_level) | 163 | QPDF_Stream::getStreamData(qpdf_stream_decode_level_e decode_level) |
| 164 | { | 164 | { |
| 165 | Pl_Buffer buf("stream data buffer"); | 165 | Pl_Buffer buf("stream data buffer"); |
| 166 | - if (! pipeStreamData(&buf, nullptr, 0, decode_level, false, false)) | 166 | + bool filtered; |
| 167 | + pipeStreamData(&buf, &filtered, 0, decode_level, false, false); | ||
| 168 | + if (! filtered) | ||
| 167 | { | 169 | { |
| 168 | throw QPDFExc(qpdf_e_unsupported, qpdf->getFilename(), | 170 | throw QPDFExc(qpdf_e_unsupported, qpdf->getFilename(), |
| 169 | "", this->offset, | 171 | "", this->offset, |
qpdf/qtest/qpdf.test
| @@ -954,12 +954,16 @@ foreach (my $i = 1; $i <= 3; ++$i) | @@ -954,12 +954,16 @@ foreach (my $i = 1; $i <= 3; ++$i) | ||
| 954 | show_ntests(); | 954 | show_ntests(); |
| 955 | # ---------- | 955 | # ---------- |
| 956 | $td->notify("--- Stream data ---"); | 956 | $td->notify("--- Stream data ---"); |
| 957 | -$n_tests += 1; | 957 | +$n_tests += 2; |
| 958 | 958 | ||
| 959 | $td->runtest("get stream data", | 959 | $td->runtest("get stream data", |
| 960 | {$td->COMMAND => "test_driver 11 stream-data.pdf"}, | 960 | {$td->COMMAND => "test_driver 11 stream-data.pdf"}, |
| 961 | {$td->FILE => "test11.out", $td->EXIT_STATUS => 0}, | 961 | {$td->FILE => "test11.out", $td->EXIT_STATUS => 0}, |
| 962 | $td->NORMALIZE_NEWLINES); | 962 | $td->NORMALIZE_NEWLINES); |
| 963 | +$td->runtest("get stream data fails on jpeg", | ||
| 964 | + {$td->COMMAND => "test_driver 68 jpeg-qstream.pdf"}, | ||
| 965 | + {$td->FILE => "test68.out", $td->EXIT_STATUS => 0}, | ||
| 966 | + $td->NORMALIZE_NEWLINES); | ||
| 963 | 967 | ||
| 964 | show_ntests(); | 968 | show_ntests(); |
| 965 | # ---------- | 969 | # ---------- |
qpdf/qtest/qpdf/jpeg-qstream.pdf
0 → 100644
No preview for this file type
qpdf/qtest/qpdf/test68.out
0 → 100644
qpdf/test_driver.cc
| @@ -2168,6 +2168,35 @@ void runtest(int n, char const* filename1, char const* arg2) | @@ -2168,6 +2168,35 @@ void runtest(int n, char const* filename1, char const* arg2) | ||
| 2168 | w.setStaticID(true); | 2168 | w.setStaticID(true); |
| 2169 | w.write(); | 2169 | w.write(); |
| 2170 | } | 2170 | } |
| 2171 | + else if (n == 68) | ||
| 2172 | + { | ||
| 2173 | + QPDFObjectHandle root = pdf.getRoot(); | ||
| 2174 | + QPDFObjectHandle qstream = root.getKey("/QStream"); | ||
| 2175 | + try | ||
| 2176 | + { | ||
| 2177 | + qstream.getStreamData(); | ||
| 2178 | + std::cout << "oops -- didn't throw" << std::endl; | ||
| 2179 | + } | ||
| 2180 | + catch (std::exception& e) | ||
| 2181 | + { | ||
| 2182 | + std::cout << "get unfilterable stream: " << e.what() | ||
| 2183 | + << std::endl; | ||
| 2184 | + } | ||
| 2185 | + PointerHolder<Buffer> b1 = qstream.getStreamData(qpdf_dl_all); | ||
| 2186 | + if ((b1->getSize() > 10) && | ||
| 2187 | + (memcmp(b1->getBuffer(), | ||
| 2188 | + "wwwwwwwww", 9) == 0)) | ||
| 2189 | + { | ||
| 2190 | + std::cout << "filtered stream data okay" << std::endl; | ||
| 2191 | + } | ||
| 2192 | + PointerHolder<Buffer> b2 = qstream.getRawStreamData(); | ||
| 2193 | + if ((b2->getSize() > 10) && | ||
| 2194 | + (memcmp(b2->getBuffer(), | ||
| 2195 | + "\xff\xd8\xff\xe0\x00\x10\x4a\x46\x49\x46", 10) == 0)) | ||
| 2196 | + { | ||
| 2197 | + std::cout << "raw stream data okay" << std::endl; | ||
| 2198 | + } | ||
| 2199 | + } | ||
| 2171 | else | 2200 | else |
| 2172 | { | 2201 | { |
| 2173 | throw std::runtime_error(std::string("invalid test ") + | 2202 | throw std::runtime_error(std::string("invalid test ") + |