[BUG] read_exp_golomb_unsigned panics/aborts on 64 or more leading zero bits (malformed SPS)

Abierto
#2,470 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@Souravrajvi0 ya está trabajando en esto.

Desde el 18/11/2026.

  • #2471 de @Souravrajvi0 — abierto

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
76/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
c, rust
Área
backend

Línea de trabajo

Start in src/rust/lib_ccxr/src/common/bitstream.rs with read_exp_golomb_unsigned, then trace the C forwarding function in cc_bitstream.c and its use from seq_parameter_set_rbsp() in avc_functions.c. Add a unit test decoding 64 zero bits and check that malformed input returns a BitstreamError rather than panicking or terminating the process; verify the SPS path can skip the NAL.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Summary
BitStreamRust::read_exp_golomb_unsigned (src/rust/lib_ccxr/src/common/bitstream.rs) does not limit the number of leading zero bits, so a short malformed H.264 SPS can panic (debug builds), return a wrong value (release builds) or terminate the process.

pub fn read_exp_golomb_unsigned(&mut self) -> Result<u64, BitstreamError> {
    let mut zeros = 0;
    while self.read_bits(1)? == 0 && self.bits_left >= 0 {
        zeros += 1;
    }
    let remaining_bits = self.read_bits(zeros)?;
    let res = ((1u64 << zeros) - 1) + remaining_bits;
    Ok(res)
}
  • Exactly 64 leading zeros: 1u64 << 64 overflows. Debug build: panicked at ... attempt to shift left with overflow. Release build: the shift count is masked, so the result is silently wrong (1u64 << 0).
  • More than 64 leading zeros: read_bits rejects bnum > 64 with fatal!, which exits the process.

Reachability
cc_bitstream.c forwards read_exp_golomb_unsigned() to this function, and seq_parameter_set_rbsp() in avc_functions.c calls it for seq_parameter_set_id. An SPS made of the 3-byte header followed by 8-9 zero bytes reaches it from do_NAL().

Reproduction
A lib_ccxr unit test that decodes 64 zero bits panics in a debug build. 9 zero bytes in an SPS makes the process exit through fatal!.

Expected
A BitstreamError that lets the caller skip the NAL.

Suggested fix
Return Err when zeros >= 64 (and have read_bits return Err instead of calling fatal! for bnum > 64). A related spot is slice_header(), which does 1 << log2_max_frame_num in C; H.264 only allows 4..16 there.

Lenguaje dominante
C
Estrellas
919
Forks
604
Merge medio
9 d 5 h
PR fusionados (30 d)
26

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de CCExtractor/ccextractor

Todos los issues de CCExtractor/ccextractor

Issues similares

Más issues de C

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.