diff --git a/ChangeLog b/ChangeLog index f0b2711b..e327b7b3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2009-02-19 Jay Berkenbilt + + * libqpdf/Pl_LZWDecoder.cc: correct logic error for previously + untested case of running the LZW decoder without the "early code + change" flag. Thanks to a bug report from "Atom Smasher", I + finally was able to obtain an input stream compressed in this way. + 2009-02-15 Jay Berkenbilt * 2.0.3: release diff --git a/libqpdf/Pl_LZWDecoder.cc b/libqpdf/Pl_LZWDecoder.cc index e85531e9..95dcec37 100644 --- a/libqpdf/Pl_LZWDecoder.cc +++ b/libqpdf/Pl_LZWDecoder.cc @@ -199,7 +199,7 @@ Pl_LZWDecoder::handleCode(int code) } } unsigned int last_idx = 258 + table_size; - if (last_idx == 4095) + if (last_idx + code_change_delta == 4096) { throw QEXC::General("LZWDecoder: table full"); } diff --git a/libtests/lzw.cc b/libtests/lzw.cc index 09ded352..034c0bb9 100644 --- a/libtests/lzw.cc +++ b/libtests/lzw.cc @@ -3,13 +3,18 @@ #include #include #include +#include -int main() +int main(int argc, char* argv[]) { + bool early_code_change = true; + if ((argc == 2) && (strcmp(argv[1], "--no-early-code-change") == 0)) + { + early_code_change = false; + } + Pl_StdioFile out("stdout", stdout); - // We don't exercise LZWDecoder with early code change false - // because we have no way to generate such an LZW stream. - Pl_LZWDecoder decode("decode", &out, true); + Pl_LZWDecoder decode("decode", &out, early_code_change); try { diff --git a/libtests/qtest/lzw.test b/libtests/qtest/lzw.test index abb412d4..649cd330 100644 --- a/libtests/qtest/lzw.test +++ b/libtests/qtest/lzw.test @@ -9,9 +9,31 @@ require TestDriver; my $td = new TestDriver('lzw'); -$td->runtest("decode", - {$td->COMMAND => "lzw < lzw1.in"}, - {$td->FILE => "lzw1.out", +cleanup(); + +$td->runtest("decode: early code change", + {$td->COMMAND => "lzw < lzw1.in > tmp"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); -$td->report(1); +$td->runtest("check output", + {$td->FILE => "tmp"}, + {$td->FILE => "lzw1.out"}); + +$td->runtest("decode: no early code change", + {$td->COMMAND => "lzw --no-early-code-change < lzw2.in > tmp"}, + {$td->STRING => "", + $td->EXIT_STATUS => 0}); + +$td->runtest("check output", + {$td->FILE => "tmp"}, + {$td->FILE => "lzw2.out"}); + +cleanup(); + +$td->report(4); + +sub cleanup +{ + unlink "tmp"; +} diff --git a/libtests/qtest/lzw/lzw2.in b/libtests/qtest/lzw/lzw2.in new file mode 100644 index 00000000..5109c45a Binary files /dev/null and b/libtests/qtest/lzw/lzw2.in differ diff --git a/libtests/qtest/lzw/lzw2.out b/libtests/qtest/lzw/lzw2.out new file mode 100644 index 00000000..ab105031 Binary files /dev/null and b/libtests/qtest/lzw/lzw2.out differ