2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 10:58:58 +00:00

fix problem with lzw decoder when run without early code change, now that we actually have test input

git-svn-id: svn+q:///qpdf/trunk@646 71b93d88-0707-0410-a8cf-f5a4172ac649
This commit is contained in:
Jay Berkenbilt 2009-02-20 02:27:36 +00:00
parent 9f93c89ee5
commit da7166bead
6 changed files with 43 additions and 9 deletions

View File

@ -1,3 +1,10 @@
2009-02-19 Jay Berkenbilt <ejb@ql.org>
* 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 <ejb@ql.org>
* 2.0.3: release

View File

@ -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");
}

View File

@ -3,13 +3,18 @@
#include <qpdf/Pl_StdioFile.hh>
#include <iostream>
#include <stdlib.h>
#include <string.h>
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
{

View File

@ -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";
}

BIN
libtests/qtest/lzw/lzw2.in Normal file

Binary file not shown.

BIN
libtests/qtest/lzw/lzw2.out Normal file

Binary file not shown.