Commit da7166bead13d09ad29f68ad64da5500c82d9be1

Authored by Jay Berkenbilt
1 parent 9f93c89e

fix problem with lzw decoder when run without early code change, now that we act…

…ually have test input

git-svn-id: svn+q:///qpdf/trunk@646 71b93d88-0707-0410-a8cf-f5a4172ac649
ChangeLog
  1 +2009-02-19 Jay Berkenbilt <ejb@ql.org>
  2 +
  3 + * libqpdf/Pl_LZWDecoder.cc: correct logic error for previously
  4 + untested case of running the LZW decoder without the "early code
  5 + change" flag. Thanks to a bug report from "Atom Smasher", I
  6 + finally was able to obtain an input stream compressed in this way.
  7 +
1 2009-02-15 Jay Berkenbilt <ejb@ql.org> 8 2009-02-15 Jay Berkenbilt <ejb@ql.org>
2 9
3 * 2.0.3: release 10 * 2.0.3: release
libqpdf/Pl_LZWDecoder.cc
@@ -199,7 +199,7 @@ Pl_LZWDecoder::handleCode(int code) @@ -199,7 +199,7 @@ Pl_LZWDecoder::handleCode(int code)
199 } 199 }
200 } 200 }
201 unsigned int last_idx = 258 + table_size; 201 unsigned int last_idx = 258 + table_size;
202 - if (last_idx == 4095) 202 + if (last_idx + code_change_delta == 4096)
203 { 203 {
204 throw QEXC::General("LZWDecoder: table full"); 204 throw QEXC::General("LZWDecoder: table full");
205 } 205 }
libtests/lzw.cc
@@ -3,13 +3,18 @@ @@ -3,13 +3,18 @@
3 #include <qpdf/Pl_StdioFile.hh> 3 #include <qpdf/Pl_StdioFile.hh>
4 #include <iostream> 4 #include <iostream>
5 #include <stdlib.h> 5 #include <stdlib.h>
  6 +#include <string.h>
6 7
7 -int main() 8 +int main(int argc, char* argv[])
8 { 9 {
  10 + bool early_code_change = true;
  11 + if ((argc == 2) && (strcmp(argv[1], "--no-early-code-change") == 0))
  12 + {
  13 + early_code_change = false;
  14 + }
  15 +
9 Pl_StdioFile out("stdout", stdout); 16 Pl_StdioFile out("stdout", stdout);
10 - // We don't exercise LZWDecoder with early code change false  
11 - // because we have no way to generate such an LZW stream.  
12 - Pl_LZWDecoder decode("decode", &out, true); 17 + Pl_LZWDecoder decode("decode", &out, early_code_change);
13 18
14 try 19 try
15 { 20 {
libtests/qtest/lzw.test
@@ -9,9 +9,31 @@ require TestDriver; @@ -9,9 +9,31 @@ require TestDriver;
9 9
10 my $td = new TestDriver('lzw'); 10 my $td = new TestDriver('lzw');
11 11
12 -$td->runtest("decode",  
13 - {$td->COMMAND => "lzw < lzw1.in"},  
14 - {$td->FILE => "lzw1.out", 12 +cleanup();
  13 +
  14 +$td->runtest("decode: early code change",
  15 + {$td->COMMAND => "lzw < lzw1.in > tmp"},
  16 + {$td->STRING => "",
  17 + $td->EXIT_STATUS => 0});
  18 +
  19 +$td->runtest("check output",
  20 + {$td->FILE => "tmp"},
  21 + {$td->FILE => "lzw1.out"});
  22 +
  23 +$td->runtest("decode: no early code change",
  24 + {$td->COMMAND => "lzw --no-early-code-change < lzw2.in > tmp"},
  25 + {$td->STRING => "",
15 $td->EXIT_STATUS => 0}); 26 $td->EXIT_STATUS => 0});
16 27
17 -$td->report(1); 28 +$td->runtest("check output",
  29 + {$td->FILE => "tmp"},
  30 + {$td->FILE => "lzw2.out"});
  31 +
  32 +cleanup();
  33 +
  34 +$td->report(4);
  35 +
  36 +sub cleanup
  37 +{
  38 + unlink "tmp";
  39 +}
libtests/qtest/lzw/lzw2.in 0 → 100644
No preview for this file type
libtests/qtest/lzw/lzw2.out 0 → 100644
No preview for this file type