Skip to content

src/ZenLib/Source/ZenLib/BitStream_Fast.h:198 Global Buffer Overflow in ZenLib::BitStream_Fast::Get4 #2610

Description

@sigdevel

src/ZenLib/Source/ZenLib/BitStream_Fast.h:198 Global Buffer Overflow in ZenLib::BitStream_Fast::Get4

Description:

When processing a crafted MP4 sample with a crafted meta/iloc box, MediaInfo crashes in ZenLib::BitStream_Fast::Get4() at src/ZenLib/Source/ZenLib/BitStream_Fast.h:198 with a global-buffer-overflow.

Get4() takes HowMany, the number of bits to read as an int8u and uses it in two places at the end of the function without checking that it fits within the declared bounds:

ToReturn |= (LastByte >> (Buffer_Size % 8)) & Mask[NewBits];
return ToReturn & Mask[HowMany];

Mask is const int32u[33], so indices 0–32 are valid. File_Mpeg4::meta_iloc() at File_Mpeg4_Elements.cpp:2717 calls Get4(80) based on a field decoded from the crafted iloc box. This causes both ToReturn = LastByte << NewBits with NewBits = 80 (undefined shift on a 32-bit type) and Mask[80] (out-of-bounds table read). UBSAN reports both violations; ASAN reports the global-buffer-overflow on the Mask access at line 198.

Output:

asan-build:

show relevant excerpt - click to expand
/run/media/user/81c71df6-ca99-4d27-a7b6-55107e347080/mediainfo/src/MediaInfoLib/Project/CMake/../../../ZenLib/Source/ZenLib/BitStream_Fast.h:184:30: runtime error: shift exponent 80 is too large for 32-bit type 'int'                                                                                                
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /run/media/user/81c71df6-ca99-4d27-a7b6-55107e347080/mediainfo/src/MediaInfoLib/Project/CMake/../../../ZenLib/Source/ZenLib/BitStream_Fast.h:184:30 
/run/media/user/81c71df6-ca99-4d27-a7b6-55107e347080/mediainfo/src/MediaInfoLib/Project/CMake/../../../ZenLib/Source/ZenLib/BitStream_Fast.h:198:47: runtime error: index 80 out of bounds for type 'const int32u[33]' (aka 'const unsigned int[33]')                                                                   
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /run/media/user/81c71df6-ca99-4d27-a7b6-55107e347080/mediainfo/src/MediaInfoLib/Project/CMake/../../../ZenLib/Source/ZenLib/BitStream_Fast.h:198:47 
=================================================================
==891440==ERROR: AddressSanitizer: global-buffer-overflow on address 0x55b400a6a120 at pc 0x55b3fddbff48 bp 0x7fffdbe87cf0 sp 0x7fffdbe87ce8
READ of size 4 at 0x55b400a6a120 thread T0                                                                                                                  
    #0 0x55b3fddbff47 in ZenLib::BitStream_Fast::Get4(unsigned char) /run/media/user/81c71df6-ca99-4d27-a7b6-55107e347080/mediainfo/src/MediaInfoLib/Project/CMake/../../../ZenLib/Source/ZenLib/BitStream_Fast.h:198:47
    #1 0x55b4001233ae in MediaInfoLib::File__Analyze::Get_BS(unsigned char, unsigned int&, char const*) /run/media/user/81c71df6-ca99-4d27-a7b6-55107e347080/mediainfo/src/MediaInfoLib/Source/MediaInfo/File__Analyze_Buffer.cpp:2122:14
    #2 0x55b3fedc95f8 in MediaInfoLib::File_Mpeg4::meta_iloc() /run/media/user/81c71df6-ca99-4d27-a7b6-55107e347080/mediainfo/src/MediaInfoLib/Source/MediaInfo/Multiple/File_Mpeg4_Elements.cpp:2717:17
    #3 0x55b3fed6da27 in MediaInfoLib::File_Mpeg4::Data_Parse() /run/media/user/81c71df6-ca99-4d27-a7b6-55107e347080/mediainfo/src/MediaInfoLib/Source/MediaInfo/Multiple/File_Mpeg4_Elements.cpp:1168:9
    #4 0x55b400049521 in MediaInfoLib::File__Analyze::Data_Manage() /run/media/user/81c71df6-ca99-4d27-a7b6-55107e347080/mediainfo/src/MediaInfoLib/Source/MediaInfo/File__Analyze.cpp:2858:9
    #5 0x55b400033e9e in MediaInfoLib::File__Analyze::Buffer_Parse() /run/media/user/81c71df6-ca99-4d27-a7b6-55107e347080/mediainfo/src/MediaInfoLib/Source/MediaInfo/File__Analyze.cpp:1961:10
    #6 0x55b40001aaa5 in MediaInfoLib::File__Analyze::Open_Buffer_Continue_Loop() /run/media/user/81c71df6-ca99-4d27-a7b6-55107e347080/mediainfo/src/MediaInfoLib/Source/MediaInfo/File__Analyze.cpp:1526:14
    #7 0x55b40000d10b in MediaInfoLib::File__Analyze::Open_Buffer_Continue(unsigned char const*, unsigned long) /run/media/user/81c71df6-ca99-4d27-a7b6-55107e347080/mediainfo/src/MediaInfoLib/Source/MediaInfo/File__Analyze.cpp:1114:16
    #8 0x55b40029984c in MediaInfoLib::File__MultipleParsing::Read_Buffer_Continue() /run/media/user/81c71df6-ca99-4d27-a7b6-55107e347080/mediainfo/src/MediaInfoLib/Source/MediaInfo/File__MultipleParsing.cpp:950:22
    #9 0x55b400019d6c in MediaInfoLib::File__Analyze::Open_Buffer_Continue_Loop() /run/media/user/81c71df6-ca99-4d27-a7b6-55107e347080/mediainfo/src/MediaInfoLib/Source/MediaInfo/File__Analyze.cpp:1501:5
    #10 0x55b40000d10b in MediaInfoLib::File__Analyze::Open_Buffer_Continue(unsigned char const*, unsigned long) /run/media/user/81c71df6-ca99-4d27-a7b6-55107e347080/mediainfo/src/MediaInfoLib/Source/MediaInfo/File__Analyze.cpp:1114:16
    #11 0x55b3fdbb6057 in MediaInfoLib::MediaInfo_Internal::Open_Buffer_Continue(unsigned char const*, unsigned long) /run/media/user/81c71df6-ca99-4d27-a7b6-55107e347080/mediainfo/src/MediaInfoLib/Source/MediaInfo/MediaInfo_Internal.cpp:1723:11
    #12 0x55b3fda5cebb in MediaInfoLib::MediaInfo::Open_Buffer_Continue(unsigned char const*, unsigned long) /run/media/user/81c71df6-ca99-4d27-a7b6-55107e347080/mediainfo/src/MediaInfoLib/Source/MediaInfo/MediaInfo.cpp:110:22
    #13 0x55b3fda5c12f in run_one(MediaInfoLib::MediaInfo&, unsigned char const*, unsigned long) /run/media/user/81c71df6-ca99-4d27-a7b6-55107e347080/mediainfo/runtime/fuzz_harness/fuzz_mediainfo.cpp:53:28
    #14 0x55b3fda5c12f in main /run/media/user/81c71df6-ca99-4d27-a7b6-55107e347080/mediainfo/runtime/fuzz_harness/fuzz_mediainfo.cpp:101:5
    #15 0x7f0e57f3df74 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
    #16 0x7f0e57f3e026 in __libc_start_main csu/../csu/libc-start.c:360:3
    #17 0x55b3fd978830 in _start (/run/media/user/81c71df6-ca99-4d27-a7b6-55107e347080/mediainfo/runtime/fuzz_harness/fuzz_mediainfo_asan+0x2313830) (BuildId: bea5f1543242f0d0639eacc3bc8ac2978314c4a4)

0x55b400a6a120 is located 32 bytes before global variable 'MediaInfoLib::AC3_MLP_Resolution' defined in '/run/media/user/81c71df6-ca99-4d27-a7b6-55107e347080/mediainfo/src/MediaInfoLib/Source/MediaInfo/Audio/File_Ac3.cpp:857' (0x55b400a6a140) of size 64                                                           
0x55b400a6a120 is located 0 bytes after global variable 'MediaInfoLib::AC3_MLP_Channels' defined in '/run/media/user/81c71df6-ca99-4d27-a7b6-55107e347080/mediainfo/src/MediaInfoLib/Source/MediaInfo/Audio/File_Ac3.cpp:820' (0x55b400a6a0a0) of size 128                                                              
SUMMARY: AddressSanitizer: global-buffer-overflow /run/media/user/81c71df6-ca99-4d27-a7b6-55107e347080/mediainfo/src/MediaInfoLib/Project/CMake/../../../ZenLib/Source/ZenLib/BitStream_Fast.h:198:47 in ZenLib::BitStream_Fast::Get4(unsigned char)
Shadow bytes around the buggy address:
  0x55b400a69e80: 04 f9 f9 f9 04 f9 f9 f9 04 f9 f9 f9 04 f9 f9 f9
  0x55b400a69f00: 03 f9 f9 f9 03 f9 f9 f9 00 00 05 f9 f9 f9 f9 f9
  0x55b400a69f80: 00 00 00 00 00 00 07 f9 f9 f9 f9 f9 00 00 00 00
  0x55b400a6a000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x55b400a6a080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x55b400a6a100: 00 00 00 00[f9]f9 f9 f9 00 00 00 00 00 00 00 00
  0x55b400a6a180: f9 f9 f9 f9 00 00 00 00 00 00 00 00 00 00 00 00
  0x55b400a6a200: 00 00 00 05 f9 f9 f9 f9 00 00 03 f9 f9 f9 f9 f9
  0x55b400a6a280: 00 00 06 f9 f9 f9 f9 f9 00 00 00 01 f9 f9 f9 f9
  0x55b400a6a300: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x55b400a6a380: 00 01 f9 f9 f9 f9 f9 f9 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==891440==ABORTING

Environment

OS: Linux rack1 6.19.14+kali-amd64 #1 SMP PREEMPT_DYNAMIC Kali 6.19.14-1+kali1 (2026-05-05) x86_64 GNU/Linux ;
Compiler version: Debian clang version 21.1.8 (3+b1) ;
Build-opts: -fsanitize=address,undefined -g ;
CPU type: x86_64 ;
MediaInfo - commit hash c1b98df276b93c95849380248e82acb8554def26 ;
MediaInfo version - 26.01 ;

Additional context

sample:

mediainfo_7

Screenshot

screen

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