[security] filters/mux_isom.c:4871 NULL Pointer Dereference in mp4_mux_cenc_update

Open
#4,072 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
58/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
c
Domain
security

Research direction

Start at mp4_mux_cenc_update (filters/mux_isom.c:4871), reached from mp4_mux_process_sample (line 5444), and trace how the crypt-session/protection context is meant to be populated — it stays NULL because the CENC IV size and key info are rejected upstream. Run an ASAN build of MP4Box against the attached sample to confirm the crash, then check where the invalid key info is detected so the mux path can bail out before dereferencing. Done means the crafted file no longer segfaults but fails cleanly or muxes correctly.

Written by the indexing model from the issue text.

Description

filters/mux_isom.c:4871 NULL Pointer Dereference in mp4_mux_cenc_update

Description:

While importing a crafted MP4 file with malformed CENC (ISO/IEC 23001-7) protection signaling, mp4_mux_process_sample (filters/mux_isom.c:5444) calls mp4_mux_cenc_update (filters/mux_isom.c:4871) to update the per-sample encryption information. The input carries an invalid CENC IV size and invalid key info (MP4Box reports Invalid CENC IV size 29, must be 8 or 16 and [MP4Mux] Invalid CENC key info), so the expected crypt-session / protection context pointer is never populated. mp4_mux_cenc_update then dereferences this NULL context, reading offset 0x8 from a NULL base pointer, which raises SIGSEGV. AddressSanitizer reports SEGV on unknown address 0x000000000008 (READ access, zero page).

To Reproduce

Steps to reproduce the behavior:

./MP4Box -add ./225_mp4_mux_cenc_update_filters_mux_isom_c_4871.mp4 /dev/null
Output:

asan-build:

==403729==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000008 (pc 0x7ff5afd838c3 bp 0x7d85ad5f5e80 sp 0x7ffd5b55d360 T0)
==403729==The signal is caused by a READ memory access.
==403729==Hint: address points to the zero page.
    #0 0x7ff5afd838c3 in mp4_mux_cenc_update filters/mux_isom.c:4871
    #1 0x7ff5afd89fc7 in mp4_mux_process_sample filters/mux_isom.c:5444
    #2 0x7ff5afdb8289 in mp4_mux_process filters/mux_isom.c:8173
    #3 0x7ff5afa76169 in gf_filter_process_task filter_core/filter.c:3257
    #4 0x7ff5afa46f03 in gf_fs_thread_proc filter_core/filter_session.c:2420
    #5 0x7ff5afa4bf7c in gf_fs_run filter_core/filter_session.c:2728
    #6 0x7ff5af4c64fb in gf_media_import media_tools/media_import.c:1639
    #7 0x5572eaab7efd in import_file /run/media/user/8ed8205b-4114-4c2a-b2d0-e2ad6640262d/gpac/runtime/gpac_asan/applications/mp4box/fileimport.c:1733
    #8 0x5572eaa72b5c in do_add_cat /run/media/user/8ed8205b-4114-4c2a-b2d0-e2ad6640262d/gpac/runtime/gpac_asan/applications/mp4box/mp4box.c:4679
    #9 0x5572eaa7523b in mp4box_main /run/media/user/8ed8205b-4114-4c2a-b2d0-e2ad6640262d/gpac/runtime/gpac_asan/applications/mp4box/mp4box.c:6447
    #10 0x7ff5ae833fb9 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:59
    #11 0x7ff5ae8340d6 in __libc_start_main_impl ../csu/libc-start.c:360
    #12 0x5572eaa530c0 in _start (/run/media/user/8ed8205b-4114-4c2a-b2d0-e2ad6640262d/gpac/runtime/gpac_asan/bin/gcc/MP4Box+0x4e0c0) (BuildId: d055c5484f27068a8903997f49222289a37b0af7)

==403729==Register values:
rax = 0x0000000000000000  rbx = 0x00007bf5ac224480  rcx = 0x0000000000000000  rdx = 0x0000000000000001  
rdi = 0x00007d65ad5f4b14  rsi = 0x00007d45ad5f7000  rbp = 0x00007d85ad5f5e80  rsp = 0x00007ffd5b55d360  
 r8 = 0x00007d55ad5e0f80   r9 = 0x0000000053414953  r10 = 0x00007cd5ad5e1da0  r11 = 0x0000000000000000  
r12 = 0x00000f7eb5844890  r13 = 0x0000000000000010  r14 = 0x00007d65ad5f4980  r15 = 0x00007c25ad5eb6e0  
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV filters/mux_isom.c:4871 in mp4_mux_cenc_update
Environment
OS: tested at 7.1.5+kali-amd64 x86_64 GNU/Linux ;
Compiler version: GCC 15.3.0-2 ;
CPU type: x86_64 ;
MP4Box - GPAC commit hash 425ef34eecf4583cf1163baca1df772e91a0ce35 ;
MP4Box - GPAC version 26.08-DEV-rev397-g425ef34ee-master ;
Additional context

link to the sample (github-url):

225_mp4_mux_cenc_update_filters_mux_isom_c_4871.mp4

Screenshots

screen

screen

Dominant language
C
Stars
3.3k
Forks
601
Avg merge
3d 17h
Merged PRs (30d)
22

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from gpac/gpac

All issues in gpac/gpac

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.