Skip to content

Commit 97dc048

Browse files
Merge pull request #14350 from Snuffleupagus/ccitt-infinite-loop
Prevent an infinite loop when parsing corrupt /CCITTFaxDecode data (issue 14305)
2 parents b178985 + e856217 commit 97dc048

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

src/core/ccitt.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* license.
2020
*/
2121

22-
import { info } from "../shared/util.js";
22+
import { FormatError, info } from "../shared/util.js";
2323

2424
/**
2525
* @typedef {Object} CCITTFaxDecoderSource
@@ -811,6 +811,12 @@ class CCITTFaxDecoder {
811811
bits = 8;
812812
c = 0;
813813
do {
814+
if (typeof this.outputBits !== "number") {
815+
throw new FormatError(
816+
'Invalid /CCITTFaxDecode data, "outputBits" must be a number.'
817+
);
818+
}
819+
814820
if (this.outputBits > bits) {
815821
c <<= bits;
816822
if (!(this.codingPos & 1)) {

test/pdfs/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -499,3 +499,4 @@
499499
!poppler-742-0-fuzzed.pdf
500500
!poppler-937-0-fuzzed.pdf
501501
!PDFBOX-3148-2-fuzzed.pdf
502+
!poppler-90-0-fuzzed.pdf

test/pdfs/poppler-90-0-fuzzed.pdf

597 KB
Binary file not shown.

test/unit/api_spec.js

+20
Original file line numberDiff line numberDiff line change
@@ -2263,6 +2263,26 @@ sozialökonomische Gerechtigkeit.`)
22632263
await loadingTask.destroy();
22642264
});
22652265

2266+
it("gets operatorList, with page resources containing corrupt /CCITTFaxDecode data", async function () {
2267+
const loadingTask = getDocument(
2268+
buildGetDocumentParams("poppler-90-0-fuzzed.pdf")
2269+
);
2270+
expect(loadingTask instanceof PDFDocumentLoadingTask).toEqual(true);
2271+
2272+
const pdfDoc = await loadingTask.promise;
2273+
expect(pdfDoc.numPages).toEqual(16);
2274+
2275+
const pdfPage = await pdfDoc.getPage(6);
2276+
expect(pdfPage instanceof PDFPageProxy).toEqual(true);
2277+
2278+
const opList = await pdfPage.getOperatorList();
2279+
expect(opList.fnArray.length).toBeGreaterThan(25);
2280+
expect(opList.argsArray.length).toBeGreaterThan(25);
2281+
expect(opList.lastChunk).toEqual(true);
2282+
2283+
await loadingTask.destroy();
2284+
});
2285+
22662286
it("gets document stats after parsing page", async function () {
22672287
await page.getOperatorList();
22682288
const stats = pdfDocument.stats;

0 commit comments

Comments
 (0)