Skip to content

Fix: leak in XML tag parsing on duplicate tag signatures (#1306)#1307

Merged
colourbill-ctrl merged 1 commit into
masterfrom
fix-1306-xml-duplicate-tag-leak
Jun 11, 2026
Merged

Fix: leak in XML tag parsing on duplicate tag signatures (#1306)#1307
colourbill-ctrl merged 1 commit into
masterfrom
fix-1306-xml-duplicate-tag-leak

Conversation

@colourbill-ctrl

Copy link
Copy Markdown
Contributor

Summary

Fixes the LeakSanitizer leak reported in #1306. iccFromXml leaks a freshly-created CIccTag when the input XML contains a duplicate tag signature (the repro has two <TagSignature>wtpt</TagSignature> entries).

Root cause

CIccProfileXml::ParseTag() creates a tag with CIccTag::Create() and then hands ownership to the profile via CIccProfile::AttachTag(). AttachTag() returns false and does not take ownership when a tag with the same signature already exists:

IccTagEntry *pEntry = GetTag(sig);
if (pEntry) {
  if (pEntry->pTag == pTag)
    return true;
  return false;          // <-- ownership NOT transferred
}

ParseTag ignored that result in two places:

  • the legacy by-type path set bAttached = true unconditionally, and
  • the by-name path discarded the return value entirely.

So on a duplicate signature the new tag was neither attached nor freed → leak. LSan trace: operator new at IccTagXmlFactory.cpp:84CIccTagXmlFactory::CreateTagCIccTag::CreateParseTag (IccProfileXml.cpp:738).

Fix

Both paths now check the AttachTag() return value; on rejection they delete pTag and fail the parse, so ownership is always well-defined. Single-file change, IccXML/IccLibXML/IccProfileXml.cpp.

Repro

wget https://raw.githubusercontent.com/xsscx/Commodity-Injection-Signatures/refs/heads/master/xml/icc/ub-member-access-null-pointer-struct-xmlnode.xml
iccFromXml ub-member-access-null-pointer-struct-xmlnode.xml oops.icc

Verification (-fsanitize=address, detect_leaks=1)

Binary Result
pre-fix LeakSanitizer: detected memory leaks — 48-byte direct leak at IccTagXmlFactory.cpp:84 (matches the issue)
post-fix leak-clean (0 LSan reports), parse fails gracefully
srgbRef.xml / argbRef.xml round-trip (post-fix) exit 0, valid ICC produced, no leak, no double-free

Fixes #1306

CIccProfileXml::ParseTag created a tag via CIccTag::Create() and then
called AttachTag() to transfer ownership to the profile.  AttachTag()
refuses (returns false) and does NOT take ownership when a tag with the
same signature is already present, but ParseTag ignored that result:

  - the legacy-by-type path unconditionally set bAttached=true, and
  - the by-name path discarded the return value entirely,

so a duplicate tag signature in the input XML leaked the freshly created
tag.  LeakSanitizer reported the allocation at
IccTagXmlFactory.cpp:84 (CIccTagXmlFactory::CreateTag) via
ParseTag -> CIccTag::Create.

Both paths now delete pTag and fail the parse when AttachTag() rejects
the tag, so ownership is always well-defined.

Repro (duplicate <TagSignature>wtpt</TagSignature>):
  iccFromXml ub-member-access-null-pointer-struct-xmlnode.xml oops.icc

Verified with -fsanitize=address: pre-fix reports the 48-byte direct
leak from the issue; post-fix is leak-clean.  srgbRef/argbRef round-trip
unchanged (exit 0, no double-free).

Fixes #1306

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions github-actions Bot added Source C or C++ source code changes pending CI checks still running passed All CI checks passed and removed pending CI checks still running labels Jun 11, 2026

@xsscx xsscx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2026-06-11 21:20:44 UTC

@xsscx xsscx removed the request for review from maxderhak June 11, 2026 21:21
@github-actions github-actions Bot added the Merge Ready Approved, mergeable, and all CI checks passed label Jun 11, 2026
@colourbill-ctrl colourbill-ctrl merged commit 02d2dcb into master Jun 11, 2026
24 checks passed
@colourbill-ctrl colourbill-ctrl deleted the fix-1306-xml-duplicate-tag-leak branch June 11, 2026 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merge Ready Approved, mergeable, and all CI checks passed passed All CI checks passed Source C or C++ source code changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Leak in CIccTagXmlFactory::CreateTag() at IccTagXmlFactory.cpp:84

2 participants