summaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDF_Stream.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2012-07-07 23:33:45 +0200
committerJay Berkenbilt <ejb@ql.org>2012-07-07 23:33:45 +0200
commite2dedde4bdb5fa68c86d412e534a4b2750739988 (patch)
tree34f2b4ec6897d605067dd2ad39c53441f74c57e7 /libqpdf/QPDF_Stream.cc
parent8705e2e8fc1a9721b2438c09ba7e92ec673af19d (diff)
downloadqpdf-e2dedde4bdb5fa68c86d412e534a4b2750739988.tar.zst
Don't require stream data provider to know length in advance
Breaking API change: length parameter has disappeared from the StreamDataProvider version of QPDFObjectHandle::replaceStreamData since it is no longer necessary to compute it in advance. This breaking change is justified by the fact that removing the length parameter provides the caller an opportunity to simplify the calling code.
Diffstat (limited to 'libqpdf/QPDF_Stream.cc')
-rw-r--r--libqpdf/QPDF_Stream.cc62
1 files changed, 39 insertions, 23 deletions
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));
+ }
}