Handle zlib data errors better (fixes #106)

This commit is contained in:
Jay Berkenbilt 2017-07-29 12:07:19 -04:00
parent 07d6f770b2
commit 6a7d53ad2b
6 changed files with 45 additions and 23 deletions

View File

@ -1,5 +1,7 @@
2017-07-29 Jay Berkenbilt <ejb@ql.org>
* Handle zlib data errors when decoding streams. Fixes #106.
* Improve handling of files where the "stream" keyword is not
followed by proper line terminators. Fixes #104.

View File

@ -157,28 +157,36 @@ Pl_Flate::handleData(unsigned char* data, int len, int flush)
void
Pl_Flate::finish()
{
if (this->outbuf)
try
{
if (this->initialized)
{
z_stream& zstream = *(static_cast<z_stream*>(this->zdata));
unsigned char buf[1];
buf[0] = '\0';
handleData(buf, 0, Z_FINISH);
int err = Z_OK;
if (action == a_deflate)
{
err = deflateEnd(&zstream);
}
else
{
err = inflateEnd(&zstream);
}
checkError("End", err);
}
if (this->outbuf)
{
if (this->initialized)
{
z_stream& zstream = *(static_cast<z_stream*>(this->zdata));
unsigned char buf[1];
buf[0] = '\0';
handleData(buf, 0, Z_FINISH);
int err = Z_OK;
if (action == a_deflate)
{
err = deflateEnd(&zstream);
}
else
{
err = inflateEnd(&zstream);
}
checkError("End", err);
}
delete [] this->outbuf;
this->outbuf = 0;
delete [] this->outbuf;
this->outbuf = 0;
}
}
catch (std::exception& e)
{
this->getNext()->finish();
throw e;
}
this->getNext()->finish();
}

View File

@ -2206,7 +2206,7 @@ QPDF::pipeStreamData(int objid, int generation,
warn(e);
}
}
catch (std::runtime_error& e)
catch (std::exception& e)
{
if (! suppress_warnings)
{
@ -2218,7 +2218,14 @@ QPDF::pipeStreamData(int objid, int generation,
QUtil::int_to_string(generation) + ": " + e.what()));
}
}
pipeline->finish();
try
{
pipeline->finish();
}
catch (std::exception&)
{
// ignore
}
return success;
}

View File

@ -206,7 +206,7 @@ $td->runtest("remove page we don't have",
show_ntests();
# ----------
$td->notify("--- Miscellaneous Tests ---");
$n_tests += 88;
$n_tests += 89;
$td->runtest("qpdf version",
{$td->COMMAND => "qpdf --version"},
@ -229,6 +229,7 @@ foreach my $d (
["118", "other infinite loop", 2],
["119", "other infinite loop", 3],
["120", "other infinite loop", 3],
["106", "zlib data error", 3],
)
{
my ($n, $description, $exit_status) = @$d;

View File

@ -0,0 +1,4 @@
WARNING: issue-106.pdf (file position 56627): error decoding stream data for object 29 0: stream inflate: inflate: data: incorrect data check
WARNING: issue-106.pdf (file position 64303): error decoding stream data for object 30 0: stream inflate: inflate: data: incorrect data check
WARNING: issue-106.pdf (file position 67427): error decoding stream data for object 31 0: stream inflate: inflate: data: incorrect data check
qpdf: operation succeeded with warnings; resulting file may have some problems

Binary file not shown.