Skip to content

fix(test): VmafFeatureDictionary double-free + leak in test callers (ADR-0806) - #187

Closed
lusoris wants to merge 1 commit into
masterfrom
fix/feature-dictionary-ownership-0806
Closed

lusoris wants to merge 1 commit into
masterfrom
fix/feature-dictionary-ownership-0806

Conversation

@lusoris

@lusoris lusoris commented May 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • CWE-415 double-free in core/test/test_vif_skip_scale0.c: error path called vmaf_feature_dictionary_free(&opts) after vmaf_use_feature(), which already unconditionally frees opts on both success and failure paths. Fix: remove the redundant free; add opts = NULL sentinel + ADR-0806 comment.
  • CWE-401 leak in core/test/test_integer_vif_cpu_cuda_parity.c: run_cuda_vif() returned early (no CUDA device) without freeing chroma_opts, which had been allocated by the caller but never reached vmaf_use_feature(). Fix: call vmaf_feature_dictionary_free(&opts) on the early-return path (safe for NULL per API contract).
  • Corrected copyright headers to Lusoris only (per project memory, 2026-05-27).
  • ADR-0806 codifies the ownership contract: vmaf_use_feature and vmaf_model_feature_overload always take ownership of the dict argument.

No production code changed. No golden assertions touched.

Deliverables checklist

  • research digest: no digest needed: trivial memory ownership audit
  • decision matrix: in ADR-0806 ## Alternatives considered
  • AGENTS.md invariant note: no rebase-sensitive invariants
  • reproducer / smoke-test: meson test -C build --suite=fast — double-free detectable with ASan; leak detectable with LSAN
  • changelog fragment: changelog.d/fixed/0806-feature-dictionary-ownership.md
  • rebase-notes: no rebase impact — fork-added test files only

Test plan

  • meson test -C build test_vif_skip_scale0 passes
  • meson test -C build test_integer_vif_cpu_cuda_parity passes (skips gracefully without CUDA device)
  • make test (ASan + UBSan) shows no double-free or leak in affected tests
  • No Netflix golden assertion values changed

🤖 Generated with Claude Code

@lusoris
lusoris enabled auto-merge (squash) May 29, 2026 10:27
@lusoris
lusoris force-pushed the fix/feature-dictionary-ownership-0806 branch from 51894e7 to ee60d0a Compare May 29, 2026 11:33
@lusoris
lusoris disabled auto-merge May 29, 2026 11:43
@lusoris
lusoris marked this pull request as draft May 29, 2026 11:43
…llers (ADR-0806)

Two bugs in fork-local test files:

1. Double-free (CWE-415) in test_vif_skip_scale0.c: the error path called
   vmaf_feature_dictionary_free(&opts) after vmaf_use_feature(), which already
   frees opts unconditionally (both on success and failure).  Fix: remove the
   redundant free; add opts = NULL sentinel and ADR-0806 comment.

2. Leak (CWE-401) in test_integer_vif_cpu_cuda_parity.c: run_cuda_vif()
   returned early on the "no CUDA device" path without freeing chroma_opts,
   which had been allocated by the caller but never consumed by
   vmaf_use_feature().  Fix: call vmaf_feature_dictionary_free(&opts) before
   the early return (safe for NULL opts per the API contract).

Also corrects copyright headers (Lusoris only, per project memory).

Ownership contract codified in ADR-0806.

no rebase impact: all changed files are fork-added tests + docs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lusoris
lusoris force-pushed the fix/feature-dictionary-ownership-0806 branch from ee60d0a to 3dc59ae Compare May 29, 2026 12:13
@lusoris

lusoris commented May 29, 2026

Copy link
Copy Markdown
Contributor Author

Contaminated (59 files) — needs reconstruction, skipping rebase per session policy

@lusoris
lusoris marked this pull request as ready for review May 31, 2026 13:36
@lusoris
lusoris marked this pull request as draft May 31, 2026 13:54
@lusoris
lusoris marked this pull request as ready for review May 31, 2026 14:03
@lusoris

lusoris commented May 31, 2026

Copy link
Copy Markdown
Contributor Author

Closing as part of marathon cleanup 2026-05-31 (150 PRs merged today). Content likely superseded by sibling merges. Reopen if specific finding still needs work; bigger PRs preferred going forward per session feedback.

@lusoris lusoris closed this May 31, 2026
@lusoris
lusoris deleted the fix/feature-dictionary-ownership-0806 branch May 31, 2026 14:08
@lusoris
lusoris restored the fix/feature-dictionary-ownership-0806 branch May 31, 2026 18:43
@lusoris lusoris reopened this May 31, 2026
@lusoris
lusoris marked this pull request as draft May 31, 2026 18:50
@lusoris

lusoris commented Jun 1, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #515 — bundled into one PR per bigger-PRs guidance. All three diffs preserved verbatim.

@lusoris lusoris closed this Jun 1, 2026
lusoris added a commit that referenced this pull request Jun 2, 2026
…ool UAF/leak + #187 feature-dict double-free)

- GPU pool UAF: clear *pool on every init() failure path so callers can't
  double-free a dangling pointer in vmaf_gpu_picture_pool_close() (ADR-0778).
- picture_pool prealloc leak: two-pass approach — allocate all pictures first,
  then strip priv/ref; error unwind uses vmaf_picture_unref on intact pictures
  instead of manual aligned_free on already-detached data (ADR-0778 Fix-E).
- feature-dict double-free: move feature-dictionary ownership into
  feature_collector; extractors no longer free dicts they don't own (ADR-0806).

Rebased onto master (aa17751) — resolved add/add conflicts in
.github/workflows/ by keeping the core/ path refs from master.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
lusoris added a commit that referenced this pull request Jun 2, 2026
…ool UAF/leak + #187 feature-dict double-free) (#515)

- GPU pool UAF: clear *pool on every init() failure path so callers can't
  double-free a dangling pointer in vmaf_gpu_picture_pool_close() (ADR-0778).
- picture_pool prealloc leak: two-pass approach — allocate all pictures first,
  then strip priv/ref; error unwind uses vmaf_picture_unref on intact pictures
  instead of manual aligned_free on already-detached data (ADR-0778 Fix-E).
- feature-dict double-free: move feature-dictionary ownership into
  feature_collector; extractors no longer free dicts they don't own (ADR-0806).

Rebased onto master (aa17751) — resolved add/add conflicts in
.github/workflows/ by keeping the core/ path refs from master.

Co-authored-by: Lusoris <lusoris@pm.me>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
@lusoris
lusoris deleted the fix/feature-dictionary-ownership-0806 branch June 4, 2026 08:11
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.

1 participant