mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-11-26 19:01:44 +02:00
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@niedermayer.cc>
This commit is contained in:
parent
c0c6b68ddb
commit
cc072f7353
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user