Browse Source

Only skip parsing a stream in `Parser_makeFilter` when we know for sure that it is empty (PR 6372 follow-up)

For PDF files with multiple `/Filter`s, where the `/Length` entry is zero, we fail to render the file correctly. The reason is that `maybeLength` is `null` for the every filter except the first, and `!maybeLength` is thus truthy.
Hence it seems that we should completely ignore the `/Length` entry and also explicitly check `maybeLength === 0`.

Note that I've not (yet) come across a PDF file with this issue in the wild, but given all the stupid things PDF generators do I wouldn't be surprised if such a file actually exists. In order to prevent a possible future bug, I'm submitting this patch which includes a hand-edited PDF file that we currently cannot render correctly (but e.g. Adobe Reader can).
Jonas Jenwald 9 years ago
parent
commit
a22f0ae820
  1. 5
      src/core/parser.js
  2. 1
      test/pdfs/.gitignore
  3. BIN
      test/pdfs/multiple-filters-length-zero.pdf
  4. 7
      test/test_manifest.json

5
src/core/parser.js

@ -564,7 +564,10 @@ var Parser = (function ParserClosure() { @@ -564,7 +564,10 @@ var Parser = (function ParserClosure() {
return stream;
},
makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
if (stream.dict.get('Length') === 0 && !maybeLength) {
// Since the 'Length' entry in the stream dictionary can be completely
// wrong, e.g. zero for non-empty streams, only skip parsing the stream
// when we can be absolutely certain that it actually is empty.
if (maybeLength === 0) {
warn('Empty "' + name + '" stream.');
return new NullStream(stream);
}

1
test/pdfs/.gitignore vendored

@ -65,6 +65,7 @@ @@ -65,6 +65,7 @@
!simpletype3font.pdf
!sizes.pdf
!javauninstall-7r.pdf
!multiple-filters-length-zero.pdf
!issue3205r.pdf
!issue3207r.pdf
!issue3263r.pdf

BIN
test/pdfs/multiple-filters-length-zero.pdf

Binary file not shown.

7
test/test_manifest.json

@ -1544,6 +1544,13 @@ @@ -1544,6 +1544,13 @@
"lastPage": 1,
"type": "eq"
},
{ "id": "multiple-filters-length-zero",
"file": "pdfs/multiple-filters-length-zero.pdf",
"md5": "c273c3a6fb79cbf3034fe1b62b204728",
"rounds": 1,
"link": false,
"type": "eq"
},
{ "id": "issue5752",
"file": "pdfs/issue5752.pdf",
"md5": "aa20ad7cff71e9481c0cd623ddbff3b7",

Loading…
Cancel
Save