Skip to content

Commit

Permalink
Merge pull request #17340 from calixteman/issue17332
Browse files Browse the repository at this point in the history
Don't throw when there isn't enough data to get block info in flate stream
  • Loading branch information
calixteman authored Nov 26, 2023
2 parents 02a0189 + 52ea20e commit b7e943b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/core/flate_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
* license.
*/

import { FormatError, info } from "../shared/util.js";
import { DecodeStream } from "./decode_stream.js";
import { FormatError } from "../shared/util.js";

const codeLenCodeMap = new Int32Array([
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15,
Expand Down Expand Up @@ -238,6 +238,11 @@ class FlateStream extends DecodeStream {
return [codes, maxLen];
}

#endsStreamOnError(err) {
info(err);
this.eof = true;
}

readBlock() {
let buffer, len;
const str = this.str;
Expand All @@ -253,19 +258,23 @@ class FlateStream extends DecodeStream {
let b;

if ((b = str.getByte()) === -1) {
throw new FormatError("Bad block header in flate stream");
this.#endsStreamOnError("Bad block header in flate stream");
return;
}
let blockLen = b;
if ((b = str.getByte()) === -1) {
throw new FormatError("Bad block header in flate stream");
this.#endsStreamOnError("Bad block header in flate stream");
return;
}
blockLen |= b << 8;
if ((b = str.getByte()) === -1) {
throw new FormatError("Bad block header in flate stream");
this.#endsStreamOnError("Bad block header in flate stream");
return;
}
let check = b;
if ((b = str.getByte()) === -1) {
throw new FormatError("Bad block header in flate stream");
this.#endsStreamOnError("Bad block header in flate stream");
return;
}
check |= b << 8;
if (check !== (~blockLen & 0xffff) && (blockLen !== 0 || check !== 0)) {
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/issue17332.pdf.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/mozilla/pdf.js/files/13463186/test.1.pdf
9 changes: 9 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8372,5 +8372,14 @@
"lastPage": 2,
"type": "eq",
"forms": true
},
{
"id": "issue17332-annotations",
"file": "pdfs/issue17332.pdf",
"md5": "140c34d900b797e1310b1cb142a4b8e3",
"rounds": 1,
"link": true,
"type": "eq",
"annotations": true
}
]

0 comments on commit b7e943b

Please sign in to comment.