Uploaded image for project: 'phpBB'
  1. phpBB
  2. PHPBB-17692

Client-side JPEG resize can double-apply EXIF Orientation in modern browsers

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • 3.3.17
    • Attachments
    • None
    • phpBB 3.3.17
      Client-side image resizing enabled
      Browser: Firefox
      OS: Windows 11

      phpBB 3.3.17 uses the bundled Plupload/mOxie image resizing code for client-side attachment resizing.

      When a JPEG contains an EXIF Orientation value such as 6 or 8, modern browsers may already apply that orientation while decoding the image. The bundled mOxie code can then apply the EXIF orientation transform again during client-side resizing, resulting in an incorrectly rotated image.

      There is also a related metadata issue when JPEG headers are preserved. After the canvas contains pixels in their final visual orientation, the original EXIF Orientation value may be restored unchanged. This can produce a JPEG whose pixels are already upright while its EXIF metadata still declares that another rotation must be applied.

      Steps to reproduce

      1. Use phpBB 3.3.17 with client-side attachment image resizing enabled.
      1. Configure maximum image dimensions smaller than the test JPEG so that Plupload performs a resize.
      1. Attach a JPEG containing EXIF Orientation 6 or 8.
      1. Allow phpBB/Plupload to resize the image in the browser.
      1. Submit the post.
      1. Check the displayed image and the EXIF Orientation value of the resulting JPEG.

      Actual result

      The image can be rotated incorrectly because EXIF orientation is effectively applied twice, or the resized JPEG can contain already-oriented pixels while retaining the original EXIF Orientation value.

      Expected result

      EXIF orientation should be applied exactly once.

      After client-side resizing:

      • the uploaded image should have the same visual orientation as the original;
      • width and height metadata should match the resized image;
      • if the exported pixels are already in their final visual orientation, EXIF Orientation should be normalized to 1;
      • Orientation=1 JPEGs and files that are not resized should remain unaffected.

      Technical details

      The bundled mOxie image code currently:

      • reads the TIFF Orientation value and may apply _rotateToOrientaion() during resizing;
      • only allows PixelXDimension and PixelYDimension to be updated through its EXIF writer;
      • can re-inject the preserved EXIF header without normalizing Orientation to match the final canvas pixels.

      I have a working proof-of-concept fix and JPEG test files with EXIF Orientation 1, 6 and 8 that reproduce the issue.

            Unassigned Unassigned
            gvp9000 gvp9000
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: