Skip to content

Commit

Permalink
Merge pull request #19356 from Snuffleupagus/bug-1942064-2
Browse files Browse the repository at this point in the history
Replace the EXIF-block with dummy data to prevent JPEG images being rotated (bug 1942064)
  • Loading branch information
Snuffleupagus authored Jan 20, 2025
2 parents 01d542e + c4ba3ac commit 850e605
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/core/jpg.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file added test/pdfs/bug1942064.pdf
Binary file not shown.
7 changes: 7 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 850e605

Please sign in to comment.