Skip to content

[FIX] Prevent 32-bit integer overflow in process_avc_sample() bounds … - #2453

Open
yasar710 wants to merge 1 commit into
CCExtractor:masterfrom
yasar710:patch-2
Open

yasar710 wants to merge 1 commit into
CCExtractor:masterfrom
yasar710:patch-2

Conversation

@yasar710

@yasar710 yasar710 commented Nov 4, 2026

Copy link
Copy Markdown

Fixes #2443
Fixes #2449

In process_avc_sample(), the bounds check i + nal_length <= previous_index || i + nal_length > s->dataLength was evaluated in 32-bit unsigned arithmetic. A crafted nal_length near UINT32_MAX wraps around into (previous_index, s->dataLength], bypassing both checks and causing a heap-buffer-overflow read at s->data[i] (src/lib_ccx/mp4.c:99) and inside do_NAL() (src/lib_ccx/mp4.c:100).

Perform the bounds-check addition in 64-bit unsigned arithmetic (uint64_t) so i + nal_length cannot wrap around.

In raising this pull request, I confirm the following (please check boxes):

Reason for this PR:

  • This PR adds new functionality.
  • This PR fixes a bug that I have personally experienced or that a real user has reported and for which a sample exists.
  • This PR is porting code from C to Rust.

Sanity check:

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • If the PR adds new functionality, I've added it to the changelog. If it's just a bug fix, I have NOT added it to the changelog.
  • I am NOT adding new C code unless it's to fix an existing, reproducible bug.

Repro instructions:

  1. Build ccextractor with AddressSanitizer (-fsanitize=address).
  2. Run ccextractor crash-input.bin using the malformed MP4 sample attached in [Security] Heap buffer overflow (OOB read past GPAC sample buffer) in process_avc_sample() at mp4.c:99 when parsing a crafted MP4 file #2443 / [Security] Heap buffer overflow (OOB read past GPAC sample buffer) in process_avc_sample() at mp4.c:99 when parsing a crafted MP4 file #2449.
  3. Without this fix, process_avc_sample() aborts with a heap-buffer-overflow at src/lib_ccx/mp4.c:99. With this fix, the 64-bit bounds check catches the overflowed nal_length, logs the corrupted sample message, and exits cleanly.

…check (CCExtractor#2443)

Fixes CCExtractor#2443
Fixes CCExtractor#2449

In `process_avc_sample()`, the bounds check `i + nal_length <= previous_index || i + nal_length > s->dataLength` was evaluated in 32-bit unsigned arithmetic. A crafted `nal_length` near `UINT32_MAX` wraps around into `(previous_index, s->dataLength]`, bypassing both checks and causing a heap-buffer-overflow at `s->data[i]` (line 99) and inside `do_NAL()` (line 100).

Perform the addition in 64-bit unsigned arithmetic (`uint64_t`) so `i + nal_length` cannot wrap around.
@yasar710

yasar710 commented Nov 4, 2026

Copy link
Copy Markdown
Author

Hi @cfsmp3, just a quick note here as well:

The code fix is fully tested and ready for review (Docker, Mac, and Windows checks are all green).

The Linux CI checks are failing early here too because of the same ubuntu-latest / libgpac-dev infrastructure issue that I mentioned in my other PR (#2448).

Let me know if any changes are needed in the code!

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

Labels

None yet

Projects

None yet

1 participant