Fix: leak in XML tag parsing on duplicate tag signatures (#1306)#1307
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the LeakSanitizer leak reported in #1306.
iccFromXmlleaks a freshly-createdCIccTagwhen the input XML contains a duplicate tag signature (the repro has two<TagSignature>wtpt</TagSignature>entries).Root cause
CIccProfileXml::ParseTag()creates a tag withCIccTag::Create()and then hands ownership to the profile viaCIccProfile::AttachTag().AttachTag()returnsfalseand does not take ownership when a tag with the same signature already exists:ParseTagignored that result in two places:bAttached = trueunconditionally, andSo on a duplicate signature the new tag was neither attached nor freed → leak. LSan trace:
operator newatIccTagXmlFactory.cpp:84←CIccTagXmlFactory::CreateTag←CIccTag::Create←ParseTag(IccProfileXml.cpp:738).Fix
Both paths now check the
AttachTag()return value; on rejection theydelete pTagand fail the parse, so ownership is always well-defined. Single-file change,IccXML/IccLibXML/IccProfileXml.cpp.Repro
Verification (
-fsanitize=address,detect_leaks=1)LeakSanitizer: detected memory leaks— 48-byte direct leak atIccTagXmlFactory.cpp:84(matches the issue)srgbRef.xml/argbRef.xmlround-trip (post-fix)Fixes #1306