justdan96 / tsMuxer

tsMuxer is a transport stream muxer for remuxing/muxing elementary streams, EVO/VOB/MPG, MKV/MKA, MP4/MOV, TS, M2TS to TS to M2TS. Supported video codecs H.264/AVC, H.265/HEVC, VC-1, MPEG2. Supported audio codecs AAC, AC3 / E-AC3(DD+), DTS/ DTS-HD.
Apache License 2.0
877 stars 147 forks source link

heap-buffer-overflow in tsMuxer/hevc.cpp:86:29 #896

Open caoxs999 opened 2 months ago

caoxs999 commented 2 months ago

version

commit 7f8667d1e6100a5b6407340d91ad80d57d976e58 (HEAD -> master, tag: nightly-2024-06-06-02-00-53, origin/master, origin/HEAD)
Author: iwashiira <89283357+iwashiira@users.noreply.github.com>
Date:   Thu Jun 6 03:13:25 2024 +0900

    added check for negative track_id values (#882)

reproduce

cd tsMuxer
mkdir build && cd build
cmake ../ -DCMAKE_C_COMPILER=clang  -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_FLAGS="-fsanitize=address" -DCMAKE_CXX_FLAGS="-fsanitize=address"
make 
./tsmuxer poc

Information :


tsMuxeR version git-7f8667d. github.com/justdan96/tsMuxer
HEVC muxing fps is not set. Get fps from stream. Value: 6849.85
HEVC manual defined fps doesn't equal to stream fps. Change HEVC fps from 1 to 6849.85
=================================================================
==4077262==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x603000001f4b at pc 0x562182db7f93 bp 0x7ffe92b922b0 sp 0x7ffe92b922a8
READ of size 1 at 0x603000001f4b thread T0
    #0 0x562182db7f92 in HevcUnit::updateBits(int, int, unsigned int) const /AFLplusplus/tsMuxer_prev/tsMuxer/hevc.cpp:86:29
    #1 0x562182dba190 in HevcVpsUnit::setFPS(double) /AFLplusplus/tsMuxer_prev/tsMuxer/hevc.cpp:236:5
    #2 0x562182dcad34 in HEVCStreamReader::updateStreamFps(void*, unsigned char*, unsigned char*, int) /AFLplusplus/tsMuxer_prev/tsMuxer/hevcStreamReader.cpp:373:10
    #3 0x562182f228d6 in MPEGStreamReader::updateFPS(void*, unsigned char*, unsigned char*, int) /AFLplusplus/tsMuxer_prev/tsMuxer/mpegStreamReader.cpp:307:9
    #4 0x562182dc63ff in HEVCStreamReader::checkStream(unsigned char*, int) /AFLplusplus/tsMuxer_prev/tsMuxer/hevcStreamReader.cpp:69:17
    #5 0x562182e70104 in METADemuxer::detectTrackReader(unsigned char*, int, AbstractStreamReader::ContainerType, int, int) /AFLplusplus/tsMuxer_prev/tsMuxer/metaDemuxer.cpp:785:22
    #6 0x562182e6d4dd in METADemuxer::DetectStreamReader(BufferedReaderManager const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, bool) /AFLplusplus/tsMuxer_prev/tsMuxer/metaDemuxer.cpp:685:35
    #7 0x562182e03473 in detectStreamReader(char const*, MPLSParser*, bool) /AFLplusplus/tsMuxer_prev/tsMuxer/main.cpp:114:34
    #8 0x562182e0b33e in main /AFLplusplus/tsMuxer_prev/tsMuxer/main.cpp:689:17
    #9 0x7fe686d76d8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
    #10 0x7fe686d76e3f in __libc_start_main csu/../csu/libc-start.c:392:3
    #11 0x562182c3f594 in _start (/AFLplusplus/tsMuxer_prev/install/bin/tsmuxer+0x23b594) (BuildId: e84fab34fa61c261f080dbcd6a5e78289b568c7f)

0x603000001f4b is located 3 bytes after 24-byte region [0x603000001f30,0x603000001f48)
allocated by thread T0 here:
    #0 0x562182d13e0d in operator new[](unsigned long) (/AFLplusplus/tsMuxer_prev/install/bin/tsmuxer+0x30fe0d) (BuildId: e84fab34fa61c261f080dbcd6a5e78289b568c7f)
    #1 0x562182db779b in HevcUnit::decodeBuffer(unsigned char const*, unsigned char const*) /AFLplusplus/tsMuxer_prev/tsMuxer/hevc.cpp:41:19
    #2 0x562182dc6240 in HEVCStreamReader::checkStream(unsigned char*, int) /AFLplusplus/tsMuxer_prev/tsMuxer/hevcStreamReader.cpp:64:20
    #3 0x562182e70104 in METADemuxer::detectTrackReader(unsigned char*, int, AbstractStreamReader::ContainerType, int, int) /AFLplusplus/tsMuxer_prev/tsMuxer/metaDemuxer.cpp:785:22
    #4 0x562182e6d4dd in METADemuxer::DetectStreamReader(BufferedReaderManager const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, bool) /AFLplusplus/tsMuxer_prev/tsMuxer/metaDemuxer.cpp:685:35
    #5 0x562182e03473 in detectStreamReader(char const*, MPLSParser*, bool) /AFLplusplus/tsMuxer_prev/tsMuxer/main.cpp:114:34
    #6 0x562182e0b33e in main /AFLplusplus/tsMuxer_prev/tsMuxer/main.cpp:689:17
    #7 0x7fe686d76d8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16

SUMMARY: AddressSanitizer: heap-buffer-overflow /AFLplusplus/tsMuxer_prev/tsMuxer/hevc.cpp:86:29 in HevcUnit::updateBits(int, int, unsigned int) const
Shadow bytes around the buggy address:
  0x603000001c80: fa fa fd fd fd fa fa fa fd fd fd fa fa fa fd fd
  0x603000001d00: fd fd fa fa fd fd fd fa fa fa fd fd fd fa fa fa
  0x603000001d80: fd fd fd fa fa fa fd fd fd fd fa fa fd fd fd fa
  0x603000001e00: fa fa fd fd fd fa fa fa fd fd fd fd fa fa fd fd
  0x603000001e80: fd fa fa fa fd fd fd fa fa fa fd fd fd fa fa fa
=>0x603000001f00: fd fd fd fa fa fa 00 00 00[fa]fa fa fa fa fa fa
  0x603000001f80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x603000002000: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x603000002080: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x603000002100: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x603000002180: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
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
==4077262==ABORTING

poc

poc2 poc2.zip