Repository navigation
Conversation
lusoris
force-pushed
the
fix/json-model-load-failure-leak
branch
2 times, most recently
from
October 2, 2026 05:22
446bdd1 to
f75e7d4
Compare
lusoris
force-pushed
the
fix/json-model-load-failure-leak
branch
from
October 2, 2026 18:43
f75e7d4 to
2eb502f
Compare
vmaf_read_json_model() allocates the model, its feature array, its name and its knot list before it parses. When parsing fails it returned the error and left the half-built model in *model, and no caller frees it: vmaf_model_load() and vmaf_model_load_from_path() pass the error on. The vmaf tool takes this path for every model collection. It tries a single-model read first and loads the collection when that fails, so -m version=vmaf_b_v0.6.3 and -m path=model/vmaf_b_v0.6.3.json leak 2413 bytes in 4 allocations each. The scores are right, but a build with LeakSanitizer exits 1. Destroy the model and reset *model to NULL on failure. A successful read is unchanged. The new test reads a collection file as a single model and fails on master without a sanitizer, because the read hands back a non-NULL model.
lusoris
force-pushed
the
fix/json-model-load-failure-leak
branch
from
October 8, 2026 17:15
2eb502f to
c6677f8
Compare
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.
Loading any model collection with the
vmaftool leaks 2413 bytes, and a build with LeakSanitizer exits 1 although the scores are correct.Cause
vmaf_read_json_model()(libvmaf/src/read_json_model.c) allocates the model, its feature array, its name and its knot list, then parses. When parsing fails it returns the error and leaves the half-built model in*model. No caller frees it:vmaf_model_load()andvmaf_model_load_from_path()only pass the error on.The tool takes this path for every model collection.
libvmaf/tools/vmaf.ctries a single-model read first and falls back to the collection loader when that fails, which then overwrites the pointer.Reproducer
Debug build with
-Db_sanitize=address,undefined, master6ec23e8f2(reproduced there; the code is unchanged in 9e48141):./build/tools/vmaf -r src01_hrc00_576x324.yuv -d src01_hrc01_576x324.yuv -w 576 -h 324 -p 420 -b 8 \ -m path=model/vmaf_b_v0.6.3.json --frame_cnt 2 -q --json -o out.json-m version=vmaf_b_v0.6.3-m path=model/vmaf_b_v0.6.3.jsontest_modelcase, no sanitizerFix
On failure,
vmaf_read_json_model()destroys the model withvmaf_model_destroy()and resets*modeltoNULL. A successful read is unchanged. The allocation and parse steps move into a helper so there is one cleanup point.Validation
x86-64 Linux, GCC 16.2.1, Meson 1.12.1, on master
9e48141b. Rebased on master 9e48141 (2026-10-02).meson test(-Denable_float=true -Denable_checkasm=true): 25/25 on master, 25/25 here.-Db_sanitize=address,undefined -Db_lto=falsebuild: 22 pass on master, 22 pass here.test_predictandtest_pic_preallocationabort on LeakSanitizer reports andcheckasmon aheap-buffer-overflowinadm_dwt2_16, the same way they do on unpatched master; this change does not touch them.vmaf_bagging,vmaf_stddev,vmaf_ci_p95_loandvmaf_ci_p95_hi.The workflow run on this PR needs a maintainer's approval.