Commit 9646077a9d for ffmpeg
commit 9646077a9d773a43d7d1188a7df251f687b04954
Author: Michael Niedermayer <michael@niedermayer.cc>
Date: Sun Oct 11 07:24:05 2026 +0200
avformat/libmodplug: return the error of a failed read instead of passing it to ModPlug_Load()
The negative result was used as the length of the never written buffer,
libmodplug converted it to an unsigned length and parsed the buffer with
that bound.
Fixes: use of uninitialized memory
Fixes: cIsMCH26EnE2
Found during the review of https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24914
Use of uninitialized memory Replicated through UnModified FFmpeg with Valgrind
diff --git a/libavformat/libmodplug.c b/libavformat/libmodplug.c
index d9ab14b3bc..b6d0897990 100644
--- a/libavformat/libmodplug.c
+++ b/libavformat/libmodplug.c
@@ -201,6 +201,10 @@ static int modplug_read_header(AVFormatContext *s)
if (!modplug->buf)
return AVERROR(ENOMEM);
sz = avio_read(pb, modplug->buf, sz);
+ if (sz < 0) {
+ av_freep(&modplug->buf);
+ return sz;
+ }
ModPlug_GetSettings(&settings);
settings.mChannels = 2;