Research-2097: Resolving live CodeQL cpp/equality-on-floats alerts — 2026-09-24¶
- Status: Active
- Workstream: ADR-1308
- Last updated: 2026-09-24
Question¶
Current origin/master carries six live GitHub CodeQL cpp/equality-on-floats alerts:
- Alert 168:
core/src/feature/feature_name.cpp:149 - Alert 927:
core/src/predict.c:302 - Alert 1101:
core/test/test_svm_api.c:368(and companion line 504) - Alert 1201:
core/src/feature/brisque_math.h:366 - Alert 1221:
core/src/mcp/3rdparty/cJSON/cJSON.c:615 - Alert 1244:
core/test/test_cambi.c:1142
How can each site be resolved at the semantic root cause such that CodeQL fresh analysis produces zero alerts, without scanner suppression comments, query evasion, public-ABI changes, score/tolerance weakening, or modifying Netflix golden assertions?
CodeQL Rule Contract¶
CodeQL's query cpp/equality-on-floats (FloatComparison.ql) matches equality expressions:
from EqualityOperation eq, Expr left, Expr right
where left = eq.getLeftOperand() and right = eq.getRightOperand()
and left.getType() instanceof FloatingPointType
and not eq.getAnOperand().isConstant()
select eq, "Equality checks on floating point values can yield unexpected results."
Key characteristics:
- Constant Comparison Exemption: When one operand is constant (e.g.
span != 0.0ordiff == 0.0),eq.getAnOperand().isConstant()evaluates to true, so CodeQL does not flag the comparison. - Bit-pattern / Integer Comparison Exemption: Comparing integers (such as
uint32_toruint64_trepresentations copied viamemcpy) operates on integer types and is completely untouched by the floating-point query.
Semantic Analysis & Root-Cause Repairs¶
1. Alert 168: core/src/feature/feature_name.cpp:149¶
- Context:
vmaf_feature_name_dict_to_feature_nameiterates over feature options and compares incoming double option values (val) with default or already parsed values (opt_val) to avoid redundant name encoding. - Contract: Two option doubles are equal if they represent the same configuration under IEEE-754 direct equality:
- NaN is never equal even to NaN (returns false if either operand is NaN).
- Signed zeros
+0.0and-0.0are considered equal. - Same infinities
+Inf == +Infand-Inf == -Infare equal via bit identity. - All finite doubles must match bit-identically in their 64-bit IEEE-754 representation.
- Repair: Implement
option_double_equals(double a, double b). - Test:
test_feature_name_double_option_semanticsadded tocore/test/test_feature.cpp.
2. Alert 927: core/src/predict.c:302¶
- Context: In
vmaf_predict_score_at_index,st->guided_scoreis checked againstst->sentinelbefore writing to the feature collector (st->guided_score != st->sentinel). - Contract: In
vmaf_predict_score_at_index, chroma correction applies only when the guided feature matches the sentinel value (0.0). If the guided feature is non-zero, NaN, or non-finite, correction does not apply. - Repair: Implement
float_values_equal(double a, double b)where NaN is never equal to any value (including NaN), signed zeros+0.0 == -0.0are equal, same infinities are equal, and finite values compare via 64-bit IEEE representation. Use!float_values_equal(st->guided_score, st->sentinel). - Test:
test_guided_feature_sentinel_semanticsadded tocore/test/test_predict.c.
3. Alert 1101: core/test/test_svm_api.c:368 and line 504¶
- Context: SVM unit tests verify model predictions against expected class labels (
labels[0] == label1). - Contract: LibSVM labels are discrete integers representing class categories (e.g.
+1.0,-1.0,0.0). - Repair: Implement
svm_labels_equal(double a, double b)using 64-bit IEEE bit identity viamemcpywith signed-zero equivalence (+0.0 == -0.0) and same-infinity behavior, rejecting NaN (never equal). It does not usea - b == 0.0or finiteness checks. - Test:
test_svm_labels_equal_semanticsadded tocore/test/test_svm_api.c.
4. Alert 1201: core/src/feature/brisque_math.h:366¶
- Context:
brisque_range_scale(double feat, double lo, double hi)incore/src/feature/brisque_math.hasserts that the normalization spanhi - lois non-degenerate before dividing:assert(hi != lo). - Contract: The span
hi - lomust be non-zero and finite to prevent division by zero or NaN propagation. - Repair: Compute
const double span = hi - lo;and assertassert(span != 0.0 && isfinite(span));. - HISS-04 Compliance: Touched file
brisque_math.hcontainedbrisque_fit_aggd(73 LOC). Under HISS-04 (max 60 LOC for touched files),brisque_aggd_accumulate(51 LOC) was cleanly extracted, maintaining exact accumulation loop ordering. - Test: Range span edge cases added to
core/test/test_brisque.c.
5. Alert 1221: core/src/mcp/3rdparty/cJSON/cJSON.c:615¶
- Context: In
print_number(),cJSONtestselse if (d == (double)item->valueint)to determine whether a number has an exact integer representation and can be emitted without decimal points. - Contract: Upstream cJSON and the fork's vendored copy follow the build's floating-point model (including Denormals-Are-Zero / DAZ under Intel
icxfast math). - Repair: Change condition to
else if (d - (double)item->valueint == 0.0). This preserves exact upstream numerical behavior across GCC, Clang, and Intel LLVM while eliminating the alert. - Test:
test_cjsonprecision tests andtest_semgrep_vendored_scope.pypass.
6. Alert 1244: core/test/test_cambi.c:1142¶
- Context: In
check_c_values_avx2_parity(core/test/test_cambi.c:1142), SIMD AVX2 and scalarcalculate_c_valueskernel outputs are asserted equal:mu_assert("...", c_scalar[i] == c_avx2[i]). - Contract: The test is asserting that the AVX2 and scalar paths produce bit-for-bit identical single-precision floating-point results.
- Repair: Replace
c_scalar[i] == c_avx2[i]withfloat_bits_equal(c_scalar[i], c_avx2[i])comparinguint32_tbit representations viamemcpy. - Test:
test_cambi_float_bits_equal_semanticsadded tocore/test/test_cambi.c.
Verification Evidence¶
- CodeQL Fresh Database Analysis:
- Analysis of database
/home/kilian/.cache/vmafx-codeql-float-dbwith CodeQL CLI 2.27.0 using standardcpp/equality-on-floatsquery (FloatComparison.ql). - Source zip SHA-256:
d850ee7bdf63ec8287922e8ed0f25009b0dd18a5a8765ef93a18f6e6412c593cmatches exact worktree source tree. - Result: All six target alerts completely eliminated (zero target alerts) in fresh SARIF report.
- Focused & Fast Unit Tests:
meson test -C build test_cambi test_cjson test_brisque test_predict test_svm_api test_feature: 6/6 passed.meson test -C build --suite=fast: 145/145 passed.- Netflix Golden Data Gate & Investigation of Reviewer Golden Discrepancy:
- Authoritative Command:
CUDA_VISIBLE_DEVICES="" VMAF_FORCE_BACKEND=cpu PYTHONPATH=python python3 -m pytest python/test/quality_runner_test.py python/test/feature_extractor_test.py python/test/vmafexec_test.py python/test/vmafexec_feature_extractor_test.py python/test/result_test.py -v -m "not slow" --tb=short(or literalmake test-netflix-golden) - Result: 271 passed, 12 skipped, 0 failed in 151.31s.
- Reviewer Golden Discrepancy Investigation: The documented command in previous draft omitted the required environment variables:
CUDA_VISIBLE_DEVICES="" VMAF_FORCE_BACKEND=cpu. On workstation hardware with an NVIDIA GPU, running withoutCUDA_VISIBLE_DEVICES="" VMAF_FORCE_BACKEND=cpuallowedvmafexecto automatically detect and dispatch to CUDA GPU kernels for feature extraction. The GPU kernels have minor floating-point differences that exceed the 4-decimal-place tolerance (assertAlmostEqual(..., places=4)), producing exactly 10 failures inpython/test/vmafexec_test.py:test_run_vmaf_runner_with_transform_scoretest_run_vmaf_runner_with_transform_score3test_run_vmaf_runner_with_transform_score4test_run_vmaf_runner_with_transform_score_2test_run_vmaf_runner_with_transform_score_both_specifiedtest_run_vmafexec_runner_float_fextest_run_vmafexec_runner_motion_force_zerotest_run_vmafexec_runner_motion_force_zero2test_run_vmafexec_runner_set_custom_modelstest_run_vmafexec_runner_set_custom_models_enable_transformWhen the required CPU environmentCUDA_VISIBLE_DEVICES="" VMAF_FORCE_BACKEND=cpuis supplied as in the authoritativeMakefilerecipe, all 271 tests pass cleanly with zero failures. No branch regression exists in the codebase.
- Governance & Standards:
praetorctl audit: passed with 0 infractions in all 9 touched files.make format-check: passed (clang-format, black, ruff, shfmt).