mirror of
https://github.com/qpdf/qpdf.git
synced 2024-11-09 23:00:57 +00:00
Merge pull request #1257 from m-holger/fuzz
In QPDFWriter::willFilterStream remember unfilterable streams
This commit is contained in:
commit
34f557a83f
@ -1236,8 +1236,8 @@ QPDFWriter::writeTrailer(
|
|||||||
bool
|
bool
|
||||||
QPDFWriter::willFilterStream(
|
QPDFWriter::willFilterStream(
|
||||||
QPDFObjectHandle stream,
|
QPDFObjectHandle stream,
|
||||||
bool& compress_stream,
|
bool& compress_stream, // out only
|
||||||
bool& is_metadata,
|
bool& is_metadata, // out only
|
||||||
std::shared_ptr<Buffer>* stream_data)
|
std::shared_ptr<Buffer>* stream_data)
|
||||||
{
|
{
|
||||||
compress_stream = false;
|
compress_stream = false;
|
||||||
@ -1299,9 +1299,10 @@ QPDFWriter::willFilterStream(
|
|||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
"error while getting stream data for " + stream.unparse() + ": " + e.what());
|
"error while getting stream data for " + stream.unparse() + ": " + e.what());
|
||||||
}
|
}
|
||||||
if (filter && (!filtered)) {
|
if (filter && !filtered) {
|
||||||
// Try again
|
// Try again
|
||||||
filter = false;
|
filter = false;
|
||||||
|
stream.setFilterOnWrite(false);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -2543,14 +2544,20 @@ QPDFWriter::writeLinearized()
|
|||||||
{
|
{
|
||||||
// Optimize file and enqueue objects in order
|
// Optimize file and enqueue objects in order
|
||||||
|
|
||||||
auto skip_stream_parameters = [this](QPDFObjectHandle& stream) {
|
std::map<int, int> stream_cache;
|
||||||
bool compress_stream;
|
|
||||||
bool is_metadata;
|
auto skip_stream_parameters = [this, &stream_cache](QPDFObjectHandle& stream) {
|
||||||
if (willFilterStream(stream, compress_stream, is_metadata, nullptr)) {
|
auto& result = stream_cache[stream.getObjectID()];
|
||||||
return 2;
|
if (result == 0) {
|
||||||
} else {
|
bool compress_stream;
|
||||||
return 1;
|
bool is_metadata;
|
||||||
|
if (willFilterStream(stream, compress_stream, is_metadata, nullptr)) {
|
||||||
|
result = 2;
|
||||||
|
} else {
|
||||||
|
result = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
QPDF::Writer::optimize(m->pdf, m->obj, skip_stream_parameters);
|
QPDF::Writer::optimize(m->pdf, m->obj, skip_stream_parameters);
|
||||||
|
Loading…
Reference in New Issue
Block a user