2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 19:08:59 +00:00

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> 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 * Improve handling of files where the "stream" keyword is not
followed by proper line terminators. Fixes #104. followed by proper line terminators. Fixes #104.

View File

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

View File

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

View File

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