Skip to content

Declare UTF-8 in IPTC data written from cloned profiles - #3226

Merged
JimBobSquarePants merged 3 commits into
SixLabors:mainfrom
jafin:jf/iptc-utf8-cloned-profiles
Oct 28, 2026
Merged

JimBobSquarePants merged 3 commits into
SixLabors:mainfrom
jafin:jf/iptc-utf8-cloned-profiles

Conversation

@jafin

@jafin jafin commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

IptcProfile.UpdateData identified UTF-8 by comparing encoding object references. DeepClone copies the encoding object, so cloned profiles lost their UTF-8 character set declaration on save. A separate UTF8Encoding instance had the same problem. Other readers could then interpret the UTF-8 text with the wrong encoding.

The check now compares code pages. UTF-8 values write the existing 1:90 declaration (ESC % G), including values in cloned profiles. The Latin-1 control checks that its original bytes remain unchanged and no UTF-8 declaration is added. Serialization layout and parsing rules are unchanged.

The regressions extend IptcProfileTests. They check cloned profiles, a separate UTF-8 encoding instance, a cloned Latin-1 value, and repeated image cloning and JPEG saves. The JPEG tests use the existing stored 31×31 PNG input. They check the exact IPTC bytes and decoded caption text, including that repeated saves write only one declaration. The JPEG helper leaves source-image disposal to its caller; each clone has an explicit lifetime.

With the original reference comparison, all three UTF-8 regressions fail and the Latin-1 control passes. With the fix, all 215 focused IPTC tests pass in Release on .NET 10 and .NET 11, with no failures or skips. No tolerances, reference images, or public API changed.

V4 backport: #3259.

Fixes #3238

UpdateData only wrote the 1:90 Coded Character Set dataset when a value's
encoding was the Encoding.UTF8 instance. Cloning an IPTC value clones its
encoding, so a profile from a cloned image, or a value set with a caller's own
UTF8Encoding, was written without the declaration and other readers fell back
to Latin-1 for non-ASCII text. The encoding is now matched by code page.
@JimBobSquarePants
JimBobSquarePants merged commit ee0839a into SixLabors:main Oct 28, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IPTC data from a cloned profile or image is written without the 1:90 UTF-8 character set record

2 participants