AkarinVS / L-SMASH-Works

Works based on L-SMASH project; This repo focuses on the common portion and the VapourSynth plugin. AviSynth users please use https://github.com/HomeOfAviSynthPlusEvolution/L-SMASH-Works. ffmpeg 5.0+ please use ffmpeg-4.5 branch.
47 stars 11 forks source link

Fix uninitialized video_frame_info_t and audio_frame_info_t fields #21

Closed magiblot closed 2 years ago

magiblot commented 2 years ago

The video_info and audio_info arrays used to be created with lw_malloc_zero (which performs zero-initialization) but resized with realloc (which doesn't zero-initialize the newly allocated elements). When registering a new video or audio sample, the array is considered to contain one more element but not all of its fields are assigned a value. So, to avoid accessing uninitialized fields later on, zero-initialize the whole element every time a new sample is registered.

Use malloc instead of lw_malloc_zero to make it clear that the initial array is not expected to be zero-initialized.

This fixes the following complaint from Valgrind:

==51781== Conditional jump or move depends on uninitialised value(s)
==51781==    at 0x1ED80825: decide_video_seek_method (lwindex.c:528)
==51781==    by 0x1ED837BB: parse_index (lwindex.c:3360)
==51781==    by 0x1ED88E1D: lwlibav_construct_index.constprop.0 (lwindex.c:3462)
==51781==    by 0x1ED75523: UnknownInlinedFun (lwlibav_source.cpp:148)
==51781==    by 0x1ED75523: CreateLWLibavVideoSource(AVSValue, void*, IScriptEnvironment*) (lwlibav_source.cpp:394)
==51781==  Uninitialised value was created by a heap allocation
==51781==    at 0x4843CD3: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==51781==    by 0x1ED8301E: parse_index (lwindex.c:3097)
==51781==    by 0x1ED88E1D: lwlibav_construct_index.constprop.0 (lwindex.c:3462)
==51781==    by 0x1ED75523: UnknownInlinedFun (lwlibav_source.cpp:148)
==51781==    by 0x1ED75523: CreateLWLibavVideoSource(AVSValue, void*, IScriptEnvironment*) (lwlibav_source.cpp:394)
AkarinVS commented 2 years ago

Thanks!

magiblot commented 2 years ago

You are welcome!