Skip to content

Fix: leak in CIccXform::Create on failure paths (#1304)#1305

Merged
colourbill-ctrl merged 1 commit into
masterfrom
fix-1304-xform-create-leak
Jun 11, 2026
Merged

Fix: leak in CIccXform::Create on failure paths (#1304)#1305
colourbill-ctrl merged 1 commit into
masterfrom
fix-1304-xform-create-leak

Conversation

@colourbill-ctrl

Copy link
Copy Markdown
Contributor

Summary

Fixes #1304 — a LeakSanitizer-reported memory leak in CIccXform::Create().

CIccXform::Create() is documented to take ownership of pProfile, but it returned NULL on every failure path without freeing it. For an icSigColorEncodingClass profile, the original profile is deleted and replaced by an encoding-converted CIccProfile (allocated in CIccDefaultEncProfileConverter::ConvertFromParams(), IccEncoding.cpp:164). A malformed profile that converts successfully but then fails to produce an xform (AddXform → status 4) therefore leaked the converted profile.

Changes (IccProfLib/IccCmm.cpp)

  • Added delete pProfile; to all 8 early return NULL sites in Create.
  • Added an else { delete pProfile; } at the function tail to cover the break-to-bottom paths where rv is left NULL (switch defaults / empty inner switches).

SetParams() is the only place pProfile is adopted, and it only runs when rv != NULL, so the deletes are unconditional and cannot double-free.

Repro

wget https://github.com/xsscx/fuzz/raw/refs/heads/master/graphics/icc/huaf-CIccNamedColorCmm-AddXform-IccCmm_cpp-Line10564.icc
iccApplyNamedCmm test-data-rgb-8bit.txt 0 0 huaf-CIccNamedColorCmm-AddXform-IccCmm_cpp-Line10564.icc 50

Verification (ASan/LSan build)

Test Before After
Repro profile Indirect leak of 232 bytes (IccEncoding.cpp:164IccCmm.cpp:551) Clean; AddXform still returns status 4 for the malformed profile
Valid sRGB transform ok ok, exit 0, no double-free

Confirmed by stashing the fix and rebuilding: the pre-fix binary reproduces the exact LSan trace from the issue; the post-fix binary is clean. Touches only IccProfLib/IccCmm.cpp.

🤖 Generated with Claude Code

CIccXform::Create() is documented to take ownership of pProfile, but it
returned NULL on every failure path without freeing it. For an
encoding-class profile the original is converted (the encoding profile
allocated in CIccDefaultEncProfileConverter::ConvertFromParams() replaces
it), so a malformed profile that converts successfully but then fails to
produce an xform leaked the converted CIccProfile.

Free pProfile on each early `return NULL`, and add an else-branch at the
end so the break-to-bottom cases (rv left NULL) also clean up. None of the
failure paths reach SetParams(), which is the only place pProfile is
adopted, so the deletes are unconditional and safe.

Repro (LeakSanitizer): iccApplyNamedCmm test-data-rgb-8bit.txt 0 0 \
  huaf-CIccNamedColorCmm-AddXform-IccCmm_cpp-Line10564.icc 50
Before: indirect leak of 232 bytes (IccEncoding.cpp:164). After: clean,
AddXform still returns status 4 for the malformed profile.

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 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 19:06:36 UTC

@xsscx xsscx removed the request for review from maxderhak June 11, 2026 19:07
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 CIccDefaultEncProfileConverter::ConvertFromParams() at IccEncoding.cpp:164

3 participants