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

Handle empty DecodeParams array for (fixes #331)

On read, ignore /DecodeParms when empty list; on write, delete it.
Some files have been found that include an empty list for
/DecodeParms, but this is not technically compliant with the spec, and
the only sensible interpretation is to treat it as if there are no
decode parameters.
This commit is contained in:
Jay Berkenbilt 2019-06-09 17:19:07 -04:00
parent 74cc3440df
commit 31bde2f9d7
5 changed files with 26 additions and 1 deletions

View File

@ -1,3 +1,8 @@
2019-06-09 Jay Berkenbilt <ejb@ql.org>
* When /DecodeParms is an empty list, ignore it on read and delete
it on write. Fixes #331.
2019-05-18 Jay Berkenbilt <ejb@ql.org>
* 8.4.2: release

View File

@ -1604,6 +1604,14 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level,
// Suppress /Length since we will write it manually
object.removeKey("/Length");
// If /DecodeParms is an empty list, remove it.
if (object.getKey("/DecodeParms").isArray() &&
(0 == object.getKey("/DecodeParms").getArrayNItems()))
{
QTC::TC("qpdf", "QPDFWriter remove empty DecodeParms");
object.removeKey("/DecodeParms");
}
if (flags & f_filtered)
{
// We will supply our own filter and decode

View File

@ -391,6 +391,10 @@ QPDF_Stream::filterable(std::vector<std::string>& filters,
QPDFObjectHandle decode_obj = this->stream_dict.getKey("/DecodeParms");
std::vector<QPDFObjectHandle> decode_parms;
if (decode_obj.isArray() && (decode_obj.getArrayNItems() == 0))
{
decode_obj = QPDFObjectHandle::newNull();
}
if (decode_obj.isArray())
{
for (int i = 0; i < decode_obj.getArrayNItems(); ++i)

View File

@ -439,3 +439,4 @@ QPDFPageObjectHelper externalize inline image 0
QPDFPageObjectHelper keep inline image 0
qpdf image optimize colorspace 0
qpdf image optimize bits per component 0
QPDFWriter remove empty DecodeParms 0

View File

@ -847,7 +847,7 @@ $td->runtest("get stream data",
show_ntests();
# ----------
$td->notify("--- Decode parameter problems ---");
$n_tests += 4;
$n_tests += 6;
# Make sure we ignore decode parameters that we don't understand
$td->runtest("unknown decode parameters",
@ -870,6 +870,13 @@ $td->runtest("check file",
{$td->FILE => "a.pdf"},
{$td->FILE => "indirect-decode-parms-out.pdf"});
$td->runtest("decode parameters empty list",
{$td->COMMAND => "qpdf --static-id empty-decode-parms.pdf a.pdf"},
{$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check file",
{$td->FILE => "a.pdf"},
{$td->FILE => "empty-decode-parms-out.pdf"});
show_ntests();
# ----------
$td->notify("--- Cross reference streams ---");