Skip to content

scuffle-h265: SpsRbsp::parse underflows on scaling_list_pred_matrix_id_delta and MinTbLog2SizeY > CtbLog2SizeY #653

Open

Description

@kixelated

SpsRbsp::parse in 0.2.2 subtracts without checks on fields from the bitstream, so a hostile SPS panics or wraps:

  1. src/sps/scaling_list.rs:90: matrix_id - scaling_list_pred_matrix_id_delta * ... underflows when the delta is larger than matrix_id. With overflow checks off, the wrapped index then panics at :92, index out of bounds: the len is 6 but the index is 18446744073709551615, so release builds panic too. The spec bounds the delta to 0..=matrixId (or matrixId / 3 for sizeId 3), so that range check would refuse it.
  2. src/sps/mod.rs:303,305: ctb_log2_size_y - min_tb_log2_size_y in the range_check! underflows when log2_min_luma_transform_block_size_minus2 makes MinTbLog2SizeY larger than CtbLog2SizeY. Debug builds panic. Release builds wrap to a huge maximum, so the check passes. The spec requires MinTbLog2SizeY < MinCbLog2SizeY, which would refuse it first.

Reproducers (RBSP, no NAL header; nuh_layer_id 0; Main profile, 64x64 4:2:0):

fn hex(s: &str) -> Vec<u8> {
    (0..s.len()).step_by(2).map(|i| u8::from_str_radix(&s[i..i + 2], 16).unwrap()).collect()
}

// 1. sizeId 1, matrixId 0, scaling_list_pred_matrix_id_delta = 1: panics in debug and release.
let _ = scuffle_h265::SpsRbsp::parse(&hex("01010000000000000000000000a0208105febf5552ffffffff")[..], 0);
// 2. CtbLog2SizeY 3, MinTbLog2SizeY 4: "attempt to subtract with overflow" at sps/mod.rs:303.
let _ = scuffle_h265::SpsRbsp::parse(&hex("01010000000000000000000000a0208105ff7ffffffff8")[..], 0);

Found by fuzzing the H.265 path in moq-dev/moq, which parses every SPS an untrusted publisher sends. The exp-Golomb wrap is filed separately for scuffle-expgolomb.

(Written by Claude Opus 5.5)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions