Commit 4faaf2e9b8 for ffmpeg
commit 4faaf2e9b896fa9d97285a1ddcaa77c4a5107e63
Author: Michael Niedermayer <michael@niedermayer.cc>
Date: Mon Oct 12 02:07:46 2026 +0200
avcodec/ratecontrol: check the fcode and bcode of the 2-pass log
Fixes: out of array access
Fixes: DY618nKRv9YY
Found during triage of the review of https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24758
Out of array access Replicated through UnModified FFmpeg with ASAN
diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c
index 130f09b9b7..98e05601da 100644
--- a/libavcodec/ratecontrol.c
+++ b/libavcodec/ratecontrol.c
@@ -635,6 +635,11 @@ av_cold int ff_rate_control_init(MPVMainEncContext *const m)
rce->pict_type, i);
return -1;
}
+ if ((unsigned)rce->f_code > MAX_FCODE || (unsigned)rce->b_code > MAX_FCODE) {
+ av_log(avctx, AV_LOG_ERROR, "invalid fcode %d / bcode %d at line %d\n",
+ rce->f_code, rce->b_code, i);
+ return -1;
+ }
p = next;
}