Skip to content

Fix EXIF UserComment decoding across current and legacy encodings#359

Open
aladin7 wants to merge 1 commit into
Ruben2776:devfrom
aladin7:fix/324-unicode-exif-comment
Open

Fix EXIF UserComment decoding across current and legacy encodings#359
aladin7 wants to merge 1 commit into
Ruben2776:devfrom
aladin7:fix/324-unicode-exif-comment

Conversation

@aladin7

@aladin7 aladin7 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Fixes #324.

Root cause

GetUserComment decoded the complete EXIF value as ASCII, including its eight-byte character-code marker. That discarded ASCII comments and corrupted non-ASCII text. A single UTF-16LE assumption is also insufficient: Exif 3.x defines UNICODE comments as UTF-8, while older files in the wild use UTF-16 with BOM, little-endian, or big-endian byte order.

Magick.NET additionally normalizes an EXIF profile's TIFF byte order on first tag access. UserComment therefore has to be decoded before other tags when legacy text has no BOM or byte-pattern clue.

Changes

  • Interpret the EXIF UserComment character-code marker and decode only its payload.
  • Decode Exif 3.x UNICODE comments as strict UTF-8.
  • Support legacy UTF-16 BOM and byte-order variants, including big-endian CJK text.
  • Preserve ASCII, undefined-marker UTF-8, and PicView's existing prefixless comments.
  • Treat recognized but unsupported JIS as empty instead of incorrectly decoding it as UTF-8.
  • Read UserComment before other EXIF properties can normalize the profile byte order.
  • Add focused decoder tests and a serialized ViewModel regression test.

This also addresses the Chinese-text failure reported while reviewing #353.

Validation

  • dotnet build PicView.Avalonia.Win32/PicView.Avalonia.Win32.csproj --no-restore -p:Platform=x64 — succeeded with 0 errors.
  • Fifteen serialized JPEG decoder cases passed in the standalone probe.
  • Raw big-endian CJK and the complete ExifViewModel.UpdateExifValues path passed.
  • The built Windows application was launched with the big-endian test JPEG; Image information displayed the Comment as 中文.

The repository's full test project currently has unrelated compilation failures in existing navigation mocks (IImageCache, IArchiveService, and IPlatformSpecificService), so it cannot reach test execution on current dev.

@Ruben2776

Copy link
Copy Markdown
Owner

It still returns question marks when I attempt to test it manually.

From debugging, it hits the Encoding.ASCII.GetString function. If you remove the if, else if statements and just call the new DecodeUnicodeComment it works as expected.

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.

EXIF property "Comment" decoding incorrect

2 participants