avutil/hdr_dynamic_metadata: fix uninitialized bytes when color saturation is set without tone mapping #24590

Merged
michaelni merged 2 commits from michaelni/FFmpeg:ff-tmp-hdr10unini into master 2026-10-04 13:31:42 +00:00
Owner

The write loop in av_dynamic_hdr_plus_to_t35() nested the
color_saturation_mapping_flag and color_saturation_weight put_bits
calls inside the tone_mapping_flag block, while the size calculation
and the parser treat these fields as unconditional per window. When
tone_mapping_flag is 0 and color_saturation_mapping_flag is 1, fewer
bits than allocated were written, leaving uninitialized heap bytes in
the returned buffer. Move the writes outside the tone_mapping_flag
block to match.

Fixes: read of uninitialized memory
Fixes: Yy1uJcbmyeBp
Fixes: AISLE-2026-0100-00011
Found-by: Joshua Rogers joshua.rogers@aisle.com

The write loop in av_dynamic_hdr_plus_to_t35() nested the color_saturation_mapping_flag and color_saturation_weight put_bits calls inside the tone_mapping_flag block, while the size calculation and the parser treat these fields as unconditional per window. When tone_mapping_flag is 0 and color_saturation_mapping_flag is 1, fewer bits than allocated were written, leaving uninitialized heap bytes in the returned buffer. Move the writes outside the tone_mapping_flag block to match. Fixes: read of uninitialized memory Fixes: Yy1uJcbmyeBp Fixes: AISLE-2026-0100-00011 Found-by: Joshua Rogers <joshua.rogers@aisle.com>
The write loop in av_dynamic_hdr_plus_to_t35() nested the
color_saturation_mapping_flag and color_saturation_weight put_bits
calls inside the tone_mapping_flag block, while the size calculation
and the parser treat these fields as unconditional per window. When
tone_mapping_flag is 0 and color_saturation_mapping_flag is 1, fewer
bits than allocated were written, leaving uninitialized heap bytes in
the returned buffer. Move the writes outside the tone_mapping_flag
block to match.

Fixes: read of uninitialized memory
Fixes: Yy1uJcbmyeBp
Fixes: AISLE-2026-0100-00011
Found-by: Joshua Rogers <joshua.rogers@aisle.com>
tests/hdr_dynamic_metadata: Test tone_mapping_flag
All checks were successful
Backport / PR (pull_request_target) Has been skipped
Lint / Pre-Commit (pull_request) Successful in 28s
Test / Fate (Full, Linux, aarch64) (pull_request) Successful in 9m33s
Test / Fate (linux-aarch64, static, 64 bit) (pull_request) Successful in 12m13s
Test / Fate (Qemu, Linux, ppc64) (pull_request) Successful in 15m35s
Test / Fate (linux-amd64, shared, 64 bit) (pull_request) Successful in 16m10s
Test / Fate (Qemu, Linux, riscv64) (pull_request) Successful in 18m47s
Test / Fate (Qemu, Linux, mips64) (pull_request) Successful in 21m47s
Test / Fate (linux-amd64, static, 32 bit) (pull_request) Successful in 23m32s
Test / Fate (Full, Wine, win64) (pull_request) Successful in 30m24s
Autolabel / Labeler (pull_request_target) Successful in 17s
ce77b6f53d
Found during triage/review of the security report
Marcos Ashton left a comment

LGTM. I checked that the new test actually catches it: without the fix, window 1 comes back with the saturation flag at 0, and with the fix it matches the ref.

LGTM. I checked that the new test actually catches it: without the fix, window 1 comes back with the saturation flag at 0, and with the fix it matches the ref.
michaelni scheduled this pull request to auto merge when all checks succeed 2026-10-03 18:27:45 +00:00
Forgejo_Fairy left a comment

LLM-GPT-6-ASTRA: The fix and regression test look correct. I found no blocking issue in 4705e4d151 or ce77b6f53d.

The saturation flag now appears once per window outside the optional tone-mapping block, with the weight still conditional on the saturation flag. This matches the size calculation and parser. flush_put_bits() zero-pads the final partial byte; with the missing fields restored, the writer fills the advertised payload. Windows with tone mapping enabled retain the previous write order. The fixture correctly distinguishes synthetic branch coverage from Version 1 conformance: §9.4 excludes its extra window, peak-luminance matrices and saturation weight. SMPTE ST 2094-40:2020 — Dynamic Metadata for Color Volume Transform — Application #4, §§9.1 and 9.4.

My verification confirms the drafts’ central results:

  • make -j8 fate-hdr_dynamic_metadata passes at ce77b6f53d. Restoring only the writer from the parent of 4705e4d151 makes window 1 decode with saturation flag 0 instead of 1 weight=9/8, confirming MarcosAsh’s observation. Restoring the fix makes FATE pass again.
  • With the revised synthetic fixture, the old writer leaves one byte of the 72-byte returned payload dependent on the caller buffer’s previous contents. The fixed writer produces identical payloads from two different prefills. All 16 combinations of the two windows’ tone-mapping and saturation flags also preserve the flags, enabled weights and queried sizes after the fix.
  • The inspected libaom and Matroska callers forward the full returned payload length, supporting the information-disclosure impact. Joshua Rogers is credited through both authorship and the Found-by trailer.

The drafts additionally report broader validation: GLM-5.3 reports clean Valgrind results and 20,000 randomized cases; SPACE-BUNNY-ALPHA reports 600,000 instrumented cases; GROK-4.7’s design review reports 1,920 initialization/round-trip cases. These remain attributed reports, not independently reproduced results from this combining review.

A few draft points need qualification:

  • SPACE-BUNNY-ALPHA — milestone concern dismissed. The metadata explicitly targets master; the milestone title does not establish a different merge destination. There is no supported reason to ask for a target change.
  • GLM-5.3 — bounds clarification. The parser permits 15 anchors through its four-bit count. Recomputing the maximum from the inspected field widths gives 7,249 bits, or 907 bytes, rather than approximately 884 bytes. This still fits AV_HDR_PLUS_MAX_PAYLOAD_SIZE; it is not a defect in this PR.
  • GLM-5.3 / SPACE-BUNNY-ALPHA — minor, optional test follow-up. Explicit coverage of both flags being zero and a direct initialization check could be useful later, but the existing test reliably detects this regression. If adding an initialization check, compare serialization into two differently prefilled buffers: simply searching for a remaining sentinel byte can reject legitimate encoded bytes. No test expansion is needed for this security fix.

I also do not rely on SPACE-BUNNY-ALPHA’s broader claims that no in-tree producer can supply the affected combination or that this class of bug is confined to this function. The inspected parser reads the flags independently; checking this serializer and an unrelated parser does not establish a project-wide guarantee.

Classification: minor_issues_approve, solely for the optional testing follow-up; the PR can merge in its current form. This follows the supplied classification rule that non-blocking suggestions permit approval, and the Development Policy in doc/developer.texi: testing should be adequate without being excessive, backportable bug fixes should stay focused, and security researchers should receive credit. This small bugfix satisfies those criteria and needs no external-project workaround or new FATE sample.

LLM-GPT-6-ASTRA: The fix and regression test look correct. I found no blocking issue in 4705e4d151c6 or ce77b6f53d65. <!-- Scope GPT-6-ASTRA [code review]: All changed hunks and supplied discussion; surrounding serializer, size calculation, parser, public field documentation, bit-writer flushing, test helpers and reference; CTA-861-H, relevant SMPTE ST 2094-40:2020 constraints and developer.texi. Reported arm64 focused FATE and ancestor-writer negative control; no full FATE or unrelated implementation audit. Scope GPT-6-ASTRA [design review]: Both commits and discussion using the head and ancestors; serializer/parser contracts, bit-writer initialization/flushing, FATE paths, CTA-861-H, SMPTE ST 2094-40:2020 and hdr10plus_tool. Reported AArch64 FATE, negative control and all 16 two-window flag combinations with differing buffer prefills; no full-suite, other-platform or performance testing. Scope GLM-5.3 [code review]: Exhaustive review of both commits and all three changed files. Reported build, focused FATE, Valgrind, dirty-heap reproduction and 20,000 randomized round-trip cases with and without the fix. Scope SPACE-BUNNY-ALPHA [code review]: Exhaustive review of both commits and three changed files; caller inspection limited to reachability. Reported build, focused FATE, buffer-prefill reproduction and 600,000 randomized cases with bit-count instrumentation. Scope GROK-4.7 [code review]: Both commits, unchanged size calculation and parser loop. Reported test build/reference comparison and caller-buffer comparisons between the fixed and ancestor writers. Scope GROK-4.7 [design review]: Both commits, serializer/size/parser agreement, SMPTE ST 2094-40:2020 sections 8.8, 9.1 and 9.4, AArch64 focused FATE and a 1,920-payload initialization sweep; muxer re-encode FATE not rerun. Scope combiner: Verified both commit diffs against their ancestor, supplied discussion and exported review, surrounding serializer/parser, bit-writer initialization/flushing, public contracts, libaom and Matroska call sites, introducing commit, relevant developer.texi rules and SMPTE sections 9.1/9.4. Built and ran focused FATE on arm64, reproduced its failure with only the ancestor writer, restored and retested the fix, and checked all 16 two-window flag combinations with two different buffer prefills. No full FATE, end-to-end muxing or independent rerun of the drafts' large randomized/Valgrind tests. --> The saturation flag now appears once per window outside the optional tone-mapping block, with the weight still conditional on the saturation flag. This matches the size calculation and parser. `flush_put_bits()` zero-pads the final partial byte; with the missing fields restored, the writer fills the advertised payload. Windows with tone mapping enabled retain the previous write order. The fixture correctly distinguishes synthetic branch coverage from Version 1 conformance: §9.4 excludes its extra window, peak-luminance matrices and saturation weight. [SMPTE ST 2094-40:2020 — Dynamic Metadata for Color Volume Transform — Application #4, §§9.1 and 9.4](https://pub.smpte.org/pub/st2094-40/st2094-40-2020.pdf). My verification confirms the drafts’ central results: - `make -j8 fate-hdr_dynamic_metadata` passes at ce77b6f53d65. Restoring only the writer from the parent of 4705e4d151c6 makes window 1 decode with saturation flag 0 instead of `1 weight=9/8`, confirming MarcosAsh’s observation. Restoring the fix makes FATE pass again. - With the revised synthetic fixture, the old writer leaves one byte of the 72-byte returned payload dependent on the caller buffer’s previous contents. The fixed writer produces identical payloads from two different prefills. All 16 combinations of the two windows’ tone-mapping and saturation flags also preserve the flags, enabled weights and queried sizes after the fix. - The inspected libaom and Matroska callers forward the full returned payload length, supporting the information-disclosure impact. Joshua Rogers is credited through both authorship and the `Found-by` trailer. The drafts additionally report broader validation: GLM-5.3 reports clean Valgrind results and 20,000 randomized cases; SPACE-BUNNY-ALPHA reports 600,000 instrumented cases; GROK-4.7’s design review reports 1,920 initialization/round-trip cases. These remain attributed reports, not independently reproduced results from this combining review. A few draft points need qualification: - **SPACE-BUNNY-ALPHA — milestone concern dismissed.** The metadata explicitly targets `master`; the milestone title does not establish a different merge destination. There is no supported reason to ask for a target change. - **GLM-5.3 — bounds clarification.** The parser permits 15 anchors through its four-bit count. Recomputing the maximum from the inspected field widths gives 7,249 bits, or 907 bytes, rather than approximately 884 bytes. This still fits `AV_HDR_PLUS_MAX_PAYLOAD_SIZE`; it is not a defect in this PR. - **GLM-5.3 / SPACE-BUNNY-ALPHA — minor, optional test follow-up.** Explicit coverage of both flags being zero and a direct initialization check could be useful later, but the existing test reliably detects this regression. If adding an initialization check, compare serialization into two differently prefilled buffers: simply searching for a remaining sentinel byte can reject legitimate encoded bytes. No test expansion is needed for this security fix. I also do not rely on SPACE-BUNNY-ALPHA’s broader claims that no in-tree producer can supply the affected combination or that this class of bug is confined to this function. The inspected parser reads the flags independently; checking this serializer and an unrelated parser does not establish a project-wide guarantee. Classification: **minor_issues_approve**, solely for the optional testing follow-up; the PR can merge in its current form. This follows the supplied classification rule that non-blocking suggestions permit approval, and the [Development Policy in `doc/developer.texi`](https://code.ffmpeg.org/FFmpeg/FFmpeg/src/commit/ce77b6f53d655fbfc6a48af5e3a90512da1ddf33/doc/developer.texi): testing should be adequate without being excessive, backportable bug fixes should stay focused, and security researchers should receive credit. This small bugfix satisfies those criteria and needs no external-project workaround or new FATE sample.
michaelni merged commit d46f27cf94 into master 2026-10-04 13:31:42 +00:00
michaelni deleted branch ff-tmp-hdr10unini 2026-10-04 13:31:44 +00:00
Sign in to join this conversation.
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
FFmpeg/FFmpeg!24590
No description provided.