Browse Source

Merge pull request #7407 from Snuffleupagus/issue-7406

Assign the `quantizationTables` after parsing the entire JPEG image, to prevent issues when the DQT (Define Quantization Tables) marker is encountered after SOF{n} (Start of Frame) markers (issue 7406)
Tim van der Meij 9 years ago committed by GitHub
parent
commit
d03651efff
  1. 16
      src/core/jpg.js
  2. 1
      test/pdfs/.gitignore
  3. BIN
      test/pdfs/issue7406.pdf
  4. 7
      test/test_manifest.json

16
src/core/jpg.js

@ -387,6 +387,10 @@ var JpegImage = (function jpegImage() {
var p0, p1, p2, p3, p4, p5, p6, p7; var p0, p1, p2, p3, p4, p5, p6, p7;
var t; var t;
if (!qt) {
throw 'missing required Quantization Table.';
}
// inverse DCT on rows // inverse DCT on rows
for (var row = 0; row < 64; row += 8) { for (var row = 0; row < 64; row += 8) {
// gather block data // gather block data
@ -738,7 +742,8 @@ var JpegImage = (function jpegImage() {
l = frame.components.push({ l = frame.components.push({
h: h, h: h,
v: v, v: v,
quantizationTable: quantizationTables[qId] quantizationId: qId,
quantizationTable: null, // See comment below.
}); });
frame.componentIds[componentId] = l - 1; frame.componentIds[componentId] = l - 1;
offset += 3; offset += 3;
@ -822,6 +827,15 @@ var JpegImage = (function jpegImage() {
this.components = []; this.components = [];
for (i = 0; i < frame.components.length; i++) { for (i = 0; i < frame.components.length; i++) {
component = frame.components[i]; component = frame.components[i];
// Prevent errors when DQT markers are placed after SOF{n} markers,
// by assigning the `quantizationTable` entry after the entire image
// has been parsed (fixes issue7406.pdf).
var quantizationTable = quantizationTables[component.quantizationId];
if (quantizationTable) {
component.quantizationTable = quantizationTable;
}
this.components.push({ this.components.push({
output: buildComponentData(frame, component), output: buildComponentData(frame, component),
scaleX: component.h / frame.maxH, scaleX: component.h / frame.maxH,

1
test/pdfs/.gitignore vendored

@ -30,6 +30,7 @@
!issue7200.pdf !issue7200.pdf
!issue7229.pdf !issue7229.pdf
!issue7403.pdf !issue7403.pdf
!issue7406.pdf
!issue7426.pdf !issue7426.pdf
!issue7439.pdf !issue7439.pdf
!issue7446.pdf !issue7446.pdf

BIN
test/pdfs/issue7406.pdf

Binary file not shown.

7
test/test_manifest.json

@ -999,6 +999,13 @@
"rounds": 1, "rounds": 1,
"type": "eq" "type": "eq"
}, },
{ "id": "issue7406",
"file": "pdfs/issue7406.pdf",
"md5": "7a3d322d7c595a36b4470cfb6a54a2b7",
"link": false,
"rounds": 1,
"type": "eq"
},
{ "id": "protectip", { "id": "protectip",
"file": "pdfs/protectip.pdf", "file": "pdfs/protectip.pdf",
"md5": "676e7a7b8f96d04825361832b1838a93", "md5": "676e7a7b8f96d04825361832b1838a93",

Loading…
Cancel
Save