[FFmpeg-cvslog] avcodec/decode: Consider discarded samples in max_samples
Michael Niedermayer
git at videolan.org
Sun Oct 18 22:42:45 EEST 2020
ffmpeg | branch: master | Michael Niedermayer <michael at niedermayer.cc> | Fri Sep 25 23:17:13 2020 +0200| [cc072f7353d5d73d86650a68b7d79832fb4338cd] | committer: Michael Niedermayer
avcodec/decode: Consider discarded samples in max_samples
Fixes: Timeout (several minutes -> 3 sec)
Fixes: 25246/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_ALS_fuzzer-5943400661254144
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=cc072f7353d5d73d86650a68b7d79832fb4338cd
---
libavcodec/decode.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 3ef1ece25b..257abc7de4 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -318,7 +318,7 @@ static int64_t guess_correct_pts(AVCodecContext *ctx,
* returning any output, so this function needs to be called in a loop until it
* returns EAGAIN.
**/
-static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame)
+static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
{
AVCodecInternal *avci = avctx->internal;
DecodeSimpleContext *ds = &avci->ds;
@@ -411,12 +411,14 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame)
!(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
avci->skip_samples = FFMAX(0, avci->skip_samples - frame->nb_samples);
got_frame = 0;
+ *discarded_samples += frame->nb_samples;
}
if (avci->skip_samples > 0 && got_frame &&
!(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
if(frame->nb_samples <= avci->skip_samples){
got_frame = 0;
+ *discarded_samples += frame->nb_samples;
avci->skip_samples -= frame->nb_samples;
av_log(avctx, AV_LOG_DEBUG, "skip whole frame, skip left: %d\n",
avci->skip_samples);
@@ -444,6 +446,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
}
av_log(avctx, AV_LOG_DEBUG, "skip %d/%d samples\n",
avci->skip_samples, frame->nb_samples);
+ *discarded_samples += avci->skip_samples;
frame->nb_samples -= avci->skip_samples;
avci->skip_samples = 0;
}
@@ -452,6 +455,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
if (discard_padding > 0 && discard_padding <= frame->nb_samples && got_frame &&
!(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
if (discard_padding == frame->nb_samples) {
+ *discarded_samples += frame->nb_samples;
got_frame = 0;
} else {
if(avctx->pkt_timebase.num && avctx->sample_rate) {
@@ -544,9 +548,12 @@ FF_ENABLE_DEPRECATION_WARNINGS
static int decode_simple_receive_frame(AVCodecContext *avctx, AVFrame *frame)
{
int ret;
+ int64_t discarded_samples = 0;
while (!frame->buf[0]) {
- ret = decode_simple_internal(avctx, frame);
+ if (discarded_samples > avctx->max_samples)
+ return AVERROR(EAGAIN);
+ ret = decode_simple_internal(avctx, frame, &discarded_samples);
if (ret < 0)
return ret;
}
More information about the ffmpeg-cvslog
mailing list