Skip to content

Tweak the heuristic, in src/core/jpg.js, that handles JPEG images with a wildly incorrect SOF (Start of Frame) scanLines parameter (issue 10989) #12063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/core/jpg.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,16 @@ var JpegImage = (function JpegImageClosure() {
} else if (nextByte === /* EOI = */ 0xd9) {
if (parseDNLMarker) {
// NOTE: only 8-bit JPEG images are supported in this decoder.
const maybeScanLines = blockRow * 8;
const maybeScanLines = blockRow * (frame.precision === 8 ? 8 : 0);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not completely related to the patch, but a better-safe-than-sorry sort of change when I had to touch related code anyway.

// Heuristic to attempt to handle corrupt JPEG images with too
// large `scanLines` parameter, by falling back to the currently
// parsed number of scanLines when it's at least one order of
// magnitude smaller than expected (fixes issue10880.pdf).
if (maybeScanLines > 0 && maybeScanLines < frame.scanLines / 10) {
// parsed number of scanLines when it's at least (approximately)
// one order of magnitude smaller than expected (fixes
// issue10880.pdf and issue10989.pdf).
if (
maybeScanLines > 0 &&
Math.round(frame.scanLines / maybeScanLines) >= 10
) {
throw new DNLMarkerError(
"Found EOI marker (0xFFD9) while parsing scan data, " +
"possibly caused by incorrect `scanLines` parameter",
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/issue10989.pdf.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/mozilla/pdf.js/files/3410726/ArchitecturalPlanProblemPDF_2.pdf
8 changes: 8 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3746,6 +3746,14 @@
"lastPage": 7,
"type": "eq"
},
{ "id": "issue10989",
"file": "pdfs/issue10989.pdf",
"md5": "c16de154d9ae6dbeec0a113911957efe",
"rounds": 1,
"link": true,
"lastPage": 1,
"type": "eq"
},
{ "id": "issue9650",
"file": "pdfs/issue9650.pdf",
"md5": "20d50bda6b1080b6d9088811299c791e",
Expand Down