diff options
Diffstat (limited to 'libqpdf')
-rw-r--r-- | libqpdf/QPDFObjectHandle.cc | 5 | ||||
-rw-r--r-- | libqpdf/QPDF_Stream.cc | 62 | ||||
-rw-r--r-- | libqpdf/qpdf/QPDF_Stream.hh | 3 |
3 files changed, 42 insertions, 28 deletions
diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index 4d6c5f79..c8b67416 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -414,12 +414,11 @@ QPDFObjectHandle::replaceStreamData(PointerHolder<Buffer> data, void QPDFObjectHandle::replaceStreamData(PointerHolder<StreamDataProvider> provider, QPDFObjectHandle const& filter, - QPDFObjectHandle const& decode_parms, - size_t length) + QPDFObjectHandle const& decode_parms) { assertType("Stream", isStream()); dynamic_cast<QPDF_Stream*>(obj.getPointer())->replaceStreamData( - provider, filter, decode_parms, length); + provider, filter, decode_parms); } int diff --git a/libqpdf/QPDF_Stream.cc b/libqpdf/QPDF_Stream.cc index ed5fb5be..c089bcc1 100644 --- a/libqpdf/QPDF_Stream.cc +++ b/libqpdf/QPDF_Stream.cc @@ -380,24 +380,33 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool filter, this->stream_provider->provideStreamData( this->objid, this->generation, &count); qpdf_offset_t actual_length = count.getCount(); - qpdf_offset_t desired_length = - this->stream_dict.getKey("/Length").getIntValue(); - if (actual_length == desired_length) - { - QTC::TC("qpdf", "QPDF_Stream pipe use stream provider"); - } - else - { - QTC::TC("qpdf", "QPDF_Stream provider length mismatch"); - throw std::logic_error( - "stream data provider for " + - QUtil::int_to_string(this->objid) + " " + - QUtil::int_to_string(this->generation) + - " provided " + - QUtil::int_to_string(actual_length) + - " bytes instead of expected " + - QUtil::int_to_string(desired_length) + " bytes"); - } + qpdf_offset_t desired_length = 0; + if (this->stream_dict.hasKey("/Length")) + { + desired_length = this->stream_dict.getKey("/Length").getIntValue(); + if (actual_length == desired_length) + { + QTC::TC("qpdf", "QPDF_Stream pipe use stream provider"); + } + else + { + QTC::TC("qpdf", "QPDF_Stream provider length mismatch"); + throw std::logic_error( + "stream data provider for " + + QUtil::int_to_string(this->objid) + " " + + QUtil::int_to_string(this->generation) + + " provided " + + QUtil::int_to_string(actual_length) + + " bytes instead of expected " + + QUtil::int_to_string(desired_length) + " bytes"); + } + } + else + { + QTC::TC("qpdf", "QPDF_Stream provider length not provided"); + this->stream_dict.replaceKey( + "/Length", QPDFObjectHandle::newInteger(actual_length)); + } } else if (this->offset == 0) { @@ -430,12 +439,11 @@ void QPDF_Stream::replaceStreamData( PointerHolder<QPDFObjectHandle::StreamDataProvider> provider, QPDFObjectHandle const& filter, - QPDFObjectHandle const& decode_parms, - size_t length) + QPDFObjectHandle const& decode_parms) { this->stream_provider = provider; this->stream_data = 0; - replaceFilterData(filter, decode_parms, length); + replaceFilterData(filter, decode_parms, 0); } void @@ -445,6 +453,14 @@ QPDF_Stream::replaceFilterData(QPDFObjectHandle const& filter, { this->stream_dict.replaceOrRemoveKey("/Filter", filter); this->stream_dict.replaceOrRemoveKey("/DecodeParms", decode_parms); - this->stream_dict.replaceKey("/Length", - QPDFObjectHandle::newInteger((int)length)); + if (length == 0) + { + QTC::TC("qpdf", "QPDF_Stream unknown stream length"); + this->stream_dict.removeKey("/Length"); + } + else + { + this->stream_dict.replaceKey( + "/Length", QPDFObjectHandle::newInteger((int)length)); + } } diff --git a/libqpdf/qpdf/QPDF_Stream.hh b/libqpdf/qpdf/QPDF_Stream.hh index e74ae201..ce46d994 100644 --- a/libqpdf/qpdf/QPDF_Stream.hh +++ b/libqpdf/qpdf/QPDF_Stream.hh @@ -30,8 +30,7 @@ class QPDF_Stream: public QPDFObject void replaceStreamData( PointerHolder<QPDFObjectHandle::StreamDataProvider> provider, QPDFObjectHandle const& filter, - QPDFObjectHandle const& decode_parms, - size_t length); + QPDFObjectHandle const& decode_parms); // Replace object ID and generation. This may only be called if // object ID and generation are 0. It is used by QPDFObjectHandle |