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

オープン
#2,470 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@Souravrajvi0 がすでに取り組んでいます。

2026年11月18日 から。

  • #2471 @Souravrajvi0 による — オープン

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
76/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
c, rust
領域
backend

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
C
スター
919
フォーク
604
平均マージ
9日 5時間
マージ済み PR(30日)
26

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

CCExtractor/ccextractor のほかの issue

CCExtractor/ccextractor の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。