Opened 3 years ago

Closed 17 months ago

Last modified 17 months ago

#8266 closed defect (fixed)

heap-use-after-free at libavformat/mpegenc.c:626

Reported by: Suhwan Owned by:
Priority: important Component: avformat
Version: git-master Keywords: mpegps crash
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: no


Summary of the bug:
There is a heap-use-after-free at libavformat/mpegenc.c:626 in get_nb_frames

I compiled ffmpeg with "--toolchain=clang-asan" to check the memory corruption and attached log file.
How to reproduce:

% ffmpeg_g -stream_loop 5 -y -i $PoC_1 -i $PoC_2 -target vcd -loglevel 8 -map 0 -c copy -c:v:143 pcm_u16be -disposition:s:8 pcm_f32le tmp.adp

ffmpeg version N-95336-g4f4334bcbc Copyright (c) 2000-2019 the FFmpeg developers
built with clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
configuration: --cc=clang --cxx=clang++ --ld=clang --enable-debug --toolchain=clang-asan

Here's ASAN log

==18825==ERROR: AddressSanitizer: heap-use-after-free on address 0x6090001f0b50 at pc 0x0000022ba732 bp 0x7fffffffa470 sp 0x7fffffffa468
READ of size 4 at 0x6090001f0b50 thread T0
    #0 0x22ba731 in get_nb_frames ffmpeg/libavformat/mpegenc.c:626:23
    #1 0x22ba731 in flush_packet ffmpeg/libavformat/mpegenc.c:836
    #2 0x22afe3a in output_packet ffmpeg/libavformat/mpegenc.c:1106:19
    #3 0x22ac0e3 in mpeg_mux_write_packet ffmpeg/libavformat/mpegenc.c:1229:19
    #4 0x2378743 in write_packet ffmpeg/libavformat/mux.c:747:15
    #5 0x238609b in av_interleaved_write_frame ffmpeg/libavformat/mux.c:1238:15
    #6 0x63bb0e in write_packet ffmpeg/fftools/ffmpeg.c:815:11
    #7 0x6140b4 in do_streamcopy ffmpeg/fftools/ffmpeg.c
    #8 0x6140b4 in process_input_packet ffmpeg/fftools/ffmpeg.c:2736
    #9 0x64a707 in process_input ffmpeg/fftools/ffmpeg.c:4508:5
    #10 0x5e7157 in transcode_step ffmpeg/fftools/ffmpeg.c:4628:11
    #11 0x5e7157 in transcode ffmpeg/fftools/ffmpeg.c:4682
    #12 0x5db65b in main ffmpeg/fftools/ffmpeg.c:4884:9
    #13 0x7ffff5c93b96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310
    #14 0x41def9 in _start (ffmpeg_asan+0x41def9)

0x6090001f0b50 is located 16 bytes inside of 32-byte region [0x6090001f0b40,0x6090001f0b60)
freed by thread T0 here:
    #0 0x4ddbe0 in __interceptor_free.localalias.0 (ffmpeg_asan+0x4ddbe0)
    #1 0x22b30be in remove_decoded_packets ffmpeg/libavformat/mpegenc.c:994:13
    #2 0x22ade08 in output_packet ffmpeg/libavformat/mpegenc.c:1071:17

previously allocated by thread T0 here:
    #0 0x4de9e8 in posix_memalign (ffmpeg_asan+0x4de9e8)
    #1 0x8599368 in av_malloc ffmpeg/libavutil/mem.c:87:9
    #2 0x8599368 in av_mallocz ffmpeg/libavutil/mem.c:238
    #3 0x22ab73b in mpeg_mux_write_packet ffmpeg/libavformat/mpegenc.c:1188:32

SUMMARY: AddressSanitizer: heap-use-after-free ffmpeg/libavformat/mpegenc.c:626:23 in get_nb_frames

Please confirm.

Attachments (3)

log_mpegenc_626 (3.8 KB ) - added by Suhwan 3 years ago.
PoC_mpeg_1.avi (146.5 KB ) - added by Suhwan 3 years ago.
PoC_mpeg_2.avi (676.7 KB ) - added by Suhwan 3 years ago.

Download all attachments as: .zip

Change History (5)

by Suhwan, 3 years ago

Attachment: log_mpegenc_626 added

by Suhwan, 3 years ago

Attachment: PoC_mpeg_1.avi added


by Suhwan, 3 years ago

Attachment: PoC_mpeg_2.avi added


comment:1 by mkver, 17 months ago

Component: undeterminedavformat
Priority: normalimportant
Resolution: fixed
Status: newclosed

comment:2 by Carl Eugen Hoyos, 17 months ago

Keywords: mpegps crash added; asan removed
Reproduced by developer: set
Note: See TracTickets for help on using tickets.