2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 19:08:59 +00:00

Add test for bad data and bad datafile

This commit is contained in:
Jay Berkenbilt 2022-05-20 13:32:59 -04:00
parent d065098089
commit 6c2fb5b8f0
7 changed files with 156 additions and 9 deletions

2
TODO
View File

@ -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

View File

@ -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;

View File

@ -33,6 +33,8 @@ my @badfiles = (
'missing-trailer',
'missing-objects',
'obj-key-errors',
'bad-data',
'bad-datafile',
);
$n_tests += scalar(@badfiles);

View File

@ -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
}
}
}
}
}

View File

@ -0,0 +1 @@
qpdf: error while getting stream data for 4 0 R: base64-decode: base64 decode: invalid input

View File

@ -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
}
}
}
}
}

View File

@ -0,0 +1 @@
qpdf: error while getting stream data for 4 0 R: open file does not exist: No such file or directory