Skip to content

jpegr: fix EXIF offset with preceding JPEG markers - #475

Merged
DichenZhang1 merged 1 commit into
google:mainfrom
gregbenz:fix-exif-offset
Sep 18, 2026
Merged

DichenZhang1 merged 1 commit into
google:mainfrom
gregbenz:fix-exif-offset

Conversation

@gregbenz

Copy link
Copy Markdown
Contributor

Summary

When API 4 combines a compressed SDR JPEG containing EXIF with a compressed gain map, libultrahdr removes and re-adds the EXIF segment. The previous offset was calculated from libjpeg's saved-marker list, which does not include every valid JPEG marker. If COM, APP14, DQT, or marker fill bytes appeared before EXIF, the offset could point to the wrong bytes, corrupting the primary JPEG or causing recombination to fail.

This change finds the selected EXIF payload in the original JPEG header, checks the segment boundaries before copying, and handles repeated marker fill bytes while rebuilding the primary JPEG.

Regression tests cover marker ordering, distinct duplicate EXIF segments, COM, APP14, DQT, marker fill bytes, and API 4 recombination.

Fixes #474

Testing

  • Complete CMake/CTest suite with UHDR_ENABLE_WERROR=ON
  • Focused ASan/UBSan regression suite
  • Windows x64 cross-compilation with warnings treated as errors

@DichenZhang1

Copy link
Copy Markdown
Collaborator

LGTM! Thanks for diagnosing this and providing comprehensive test coverage for marker ordering, fill bytes, and unretained segments.

I have opened a small follow-up PR with minor typing and bounds hardening for find_marker_payload_offset (using uint8_t marker_code and guarding against potential long overflow): #477

@DichenZhang1
DichenZhang1 merged commit 8924e08 into google:main Sep 18, 2026
28 checks passed
@gregbenz
gregbenz deleted the fix-exif-offset branch September 19, 2026 00:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

appendGainMap: EXIF offset derived from marker_list is wrong when unsaved markers precede EXIF — corrupts base JPEG, fails with "SOS marker not found"

2 participants