diff --git a/src/core/jpg.js b/src/core/jpg.js index a7640a6d4..93d703ab9 100644 --- a/src/core/jpg.js +++ b/src/core/jpg.js @@ -817,6 +817,29 @@ class JpegImage { markerLoop: while (fileMarker !== /* EOI (End of Image) = */ 0xffd9) { switch (fileMarker) { + case 0xffe1: // APP1 - Exif + // TODO: Remove this once https://github.com/w3c/webcodecs/issues/870 + // is fixed. + const { appData, newOffset } = readDataBlock(data, offset); + offset = newOffset; + + // 'Exif\x00\x00' + if ( + appData[0] === 0x45 && + appData[1] === 0x78 && + appData[2] === 0x69 && + appData[3] === 0x66 && + appData[4] === 0 && + appData[5] === 0 + ) { + // Replace the entire EXIF-block with dummy data, to ensure that a + // non-default EXIF orientation won't cause the image to be rotated + // when using `ImageDecoder` (fixes bug1942064.pdf). + appData.fill(0x00, 6); + } + fileMarker = readUint16(data, offset); + offset += 2; + continue; case 0xffc0: // SOF0 (Start of Frame, Baseline DCT) case 0xffc1: // SOF1 (Start of Frame, Extended DCT) case 0xffc2: // SOF2 (Start of Frame, Progressive DCT) diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 74bc63780..9105960cb 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -503,6 +503,7 @@ !annotation-line-without-appearance.pdf !bug1669099.pdf !annotation-square-circle.pdf +!bug1942064.pdf !annotation-square-circle-without-appearance.pdf !annotation-stamp.pdf !issue14048.pdf diff --git a/test/pdfs/bug1942064.pdf b/test/pdfs/bug1942064.pdf new file mode 100644 index 000000000..cb9dff334 Binary files /dev/null and b/test/pdfs/bug1942064.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index 1a7418b9a..03c40750c 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -8997,6 +8997,13 @@ "link": true, "type": "other" }, + { + "id": "bug1942064", + "file": "pdfs/bug1942064.pdf", + "md5": "d50b5ebb8cab1211609d16faa54ec47d", + "rounds": 1, + "type": "eq" + }, { "id": "issue16221-text", "file": "pdfs/issue16221.pdf",