diff --git a/TODO b/TODO index ea6cf42f..eed33e6d 100644 --- a/TODO +++ b/TODO @@ -61,7 +61,7 @@ Make sure pages tree repair generates warnings. * Have a test case if possible that exercises the object description which means we need some kind of semantic error that gets caught after creation. -* Test invalid data, invalid data file +* Document that /Length is ignored in stream dictionary replacements Try to never flatten pages tree. Make sure we do something reasonable with pages tree repair. The problem is that if pages tree repair is diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc index 35041249..70c65c5d 100644 --- a/libqpdf/QPDFWriter.cc +++ b/libqpdf/QPDFWriter.cc @@ -1419,14 +1419,21 @@ QPDFWriter::willFilterStream( pushPipeline(new Pl_Buffer("stream data")); PipelinePopper pp_stream_data(this, stream_data); activatePipelineStack(pp_stream_data); - filtered = stream.pipeStreamData( - this->m->pipeline, - (((filter && normalize) ? qpdf_ef_normalize : 0) | - ((filter && compress_stream) ? qpdf_ef_compress : 0)), - (filter ? (uncompress ? qpdf_dl_all : this->m->stream_decode_level) - : qpdf_dl_none), - false, - (attempt == 1)); + try { + filtered = stream.pipeStreamData( + this->m->pipeline, + (((filter && normalize) ? qpdf_ef_normalize : 0) | + ((filter && compress_stream) ? qpdf_ef_compress : 0)), + (filter + ? (uncompress ? qpdf_dl_all : this->m->stream_decode_level) + : qpdf_dl_none), + false, + (attempt == 1)); + } catch (std::runtime_error& e) { + throw std::runtime_error( + "error while getting stream data for " + stream.unparse() + + ": " + e.what()); + } if (filter && (!filtered)) { // Try again filter = false; diff --git a/qpdf/qtest/qpdf-json.test b/qpdf/qtest/qpdf-json.test index dda056a1..22b714c5 100644 --- a/qpdf/qtest/qpdf-json.test +++ b/qpdf/qtest/qpdf-json.test @@ -33,6 +33,8 @@ my @badfiles = ( 'missing-trailer', 'missing-objects', 'obj-key-errors', + 'bad-data', + 'bad-datafile', ); $n_tests += scalar(@badfiles); diff --git a/qpdf/qtest/qpdf/qjson-bad-data.json b/qpdf/qtest/qpdf/qjson-bad-data.json new file mode 100644 index 00000000..9b8880d4 --- /dev/null +++ b/qpdf/qtest/qpdf/qjson-bad-data.json @@ -0,0 +1,68 @@ +{ + "qpdf-v2": { + "pdfversion": "1.3", + "maxobjectid": 6, + "objects": { + "obj:1 0 R": { + "value": { + "/Pages": "2 0 R", + "/Type": "/Catalog" + } + }, + "obj:2 0 R": { + "value": { + "/Count": 1, + "/Kids": [ + "3 0 R" + ], + "/Type": "/Pages" + } + }, + "obj:3 0 R": { + "value": { + "/Contents": ["4 0 R", "7 0 R"], + "/MediaBox": [ + 0, + 0, + 612, + 792 + ], + "/Parent": "2 0 R", + "/Resources": { + "/Font": { + "/F1": "6 0 R" + }, + "/ProcSet": "5 0 R" + }, + "/Type": "/Page" + } + }, + "obj:4 0 R": { + "stream": { + "data": "@not-base64@", + "dict": {} + } + }, + "obj:5 0 R": { + "value": [ + "/PDF", + "/Text" + ] + }, + "obj:6 0 R": { + "value": { + "/BaseFont": "/Helvetica", + "/Encoding": "/WinAnsiEncoding", + "/Subtype": "/Type1", + "/Type": "/Font" + } + }, + "trailer": { + "value": { + "/Root": "1 0 R", + "/Size": 7 + } + } + } + } +} diff --git a/qpdf/qtest/qpdf/qjson-bad-data.out b/qpdf/qtest/qpdf/qjson-bad-data.out new file mode 100644 index 00000000..e5cf46bb --- /dev/null +++ b/qpdf/qtest/qpdf/qjson-bad-data.out @@ -0,0 +1 @@ +qpdf: error while getting stream data for 4 0 R: base64-decode: base64 decode: invalid input diff --git a/qpdf/qtest/qpdf/qjson-bad-datafile.json b/qpdf/qtest/qpdf/qjson-bad-datafile.json new file mode 100644 index 00000000..025f700b --- /dev/null +++ b/qpdf/qtest/qpdf/qjson-bad-datafile.json @@ -0,0 +1,68 @@ +{ + "qpdf-v2": { + "pdfversion": "1.3", + "maxobjectid": 6, + "objects": { + "obj:1 0 R": { + "value": { + "/Pages": "2 0 R", + "/Type": "/Catalog" + } + }, + "obj:2 0 R": { + "value": { + "/Count": 1, + "/Kids": [ + "3 0 R" + ], + "/Type": "/Pages" + } + }, + "obj:3 0 R": { + "value": { + "/Contents": ["4 0 R", "7 0 R"], + "/MediaBox": [ + 0, + 0, + 612, + 792 + ], + "/Parent": "2 0 R", + "/Resources": { + "/Font": { + "/F1": "6 0 R" + }, + "/ProcSet": "5 0 R" + }, + "/Type": "/Page" + } + }, + "obj:4 0 R": { + "stream": { + "datafile": "file does not exist", + "dict": {} + } + }, + "obj:5 0 R": { + "value": [ + "/PDF", + "/Text" + ] + }, + "obj:6 0 R": { + "value": { + "/BaseFont": "/Helvetica", + "/Encoding": "/WinAnsiEncoding", + "/Subtype": "/Type1", + "/Type": "/Font" + } + }, + "trailer": { + "value": { + "/Root": "1 0 R", + "/Size": 7 + } + } + } + } +} diff --git a/qpdf/qtest/qpdf/qjson-bad-datafile.out b/qpdf/qtest/qpdf/qjson-bad-datafile.out new file mode 100644 index 00000000..1ef4f028 --- /dev/null +++ b/qpdf/qtest/qpdf/qjson-bad-datafile.out @@ -0,0 +1 @@ +qpdf: error while getting stream data for 4 0 R: open file does not exist: No such file or directory