Skip to content

Commit 7dabc5e

Browse files
Merge pull request #12063 from Snuffleupagus/issue-10989
Tweak the heuristic, in `src/core/jpg.js`, that handles JPEG images with a wildly incorrect SOF (Start of Frame) `scanLines` parameter (issue 10989)
2 parents c11fc3a + 1d66fce commit 7dabc5e

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/core/jpg.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,16 @@ var JpegImage = (function JpegImageClosure() {
163163
} else if (nextByte === /* EOI = */ 0xd9) {
164164
if (parseDNLMarker) {
165165
// NOTE: only 8-bit JPEG images are supported in this decoder.
166-
const maybeScanLines = blockRow * 8;
166+
const maybeScanLines = blockRow * (frame.precision === 8 ? 8 : 0);
167167
// Heuristic to attempt to handle corrupt JPEG images with too
168168
// large `scanLines` parameter, by falling back to the currently
169-
// parsed number of scanLines when it's at least one order of
170-
// magnitude smaller than expected (fixes issue10880.pdf).
171-
if (maybeScanLines > 0 && maybeScanLines < frame.scanLines / 10) {
169+
// parsed number of scanLines when it's at least (approximately)
170+
// one order of magnitude smaller than expected (fixes
171+
// issue10880.pdf and issue10989.pdf).
172+
if (
173+
maybeScanLines > 0 &&
174+
Math.round(frame.scanLines / maybeScanLines) >= 10
175+
) {
172176
throw new DNLMarkerError(
173177
"Found EOI marker (0xFFD9) while parsing scan data, " +
174178
"possibly caused by incorrect `scanLines` parameter",

test/pdfs/issue10989.pdf.link

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/mozilla/pdf.js/files/3410726/ArchitecturalPlanProblemPDF_2.pdf

test/test_manifest.json

+8
Original file line numberDiff line numberDiff line change
@@ -3746,6 +3746,14 @@
37463746
"lastPage": 7,
37473747
"type": "eq"
37483748
},
3749+
{ "id": "issue10989",
3750+
"file": "pdfs/issue10989.pdf",
3751+
"md5": "c16de154d9ae6dbeec0a113911957efe",
3752+
"rounds": 1,
3753+
"link": true,
3754+
"lastPage": 1,
3755+
"type": "eq"
3756+
},
37493757
{ "id": "issue9650",
37503758
"file": "pdfs/issue9650.pdf",
37513759
"md5": "20d50bda6b1080b6d9088811299c791e",

0 commit comments

Comments
 (0)