mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-07-04 07:18:36 +08:00
avformat/iamf_parse: prevent overreads in update_extradata
Fixes: libavcodec/put_bits.h:232:32: runtime error: shift exponent -19 is negative Fixes: Assertion n>=0 && n<=32 failed at ./libavcodec/get_bits.h:406 Fixes: 398527871/clusterfuzz-testcase-minimized-ffmpeg_dem_IAMF_fuzzer-6602025714647040 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
@ -288,7 +288,7 @@ static int update_extradata(AVCodecParameters *codecpar)
|
|||||||
uint8_t buf[6];
|
uint8_t buf[6];
|
||||||
int size = FFMIN(codecpar->extradata_size, sizeof(buf));
|
int size = FFMIN(codecpar->extradata_size, sizeof(buf));
|
||||||
|
|
||||||
init_put_bits(&pb, buf, size);
|
init_put_bits(&pb, buf, sizeof(buf));
|
||||||
ret = init_get_bits8(&gb, codecpar->extradata, size);
|
ret = init_get_bits8(&gb, codecpar->extradata, size);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
@ -304,7 +304,10 @@ static int update_extradata(AVCodecParameters *codecpar)
|
|||||||
|
|
||||||
skip_bits(&gb, 4);
|
skip_bits(&gb, 4);
|
||||||
put_bits(&pb, 4, codecpar->ch_layout.nb_channels); // set channel config
|
put_bits(&pb, 4, codecpar->ch_layout.nb_channels); // set channel config
|
||||||
ret = put_bits_left(&pb);
|
ret = get_bits_left(&gb);
|
||||||
|
if (ret < 0)
|
||||||
|
return AVERROR_INVALIDDATA;
|
||||||
|
ret = FFMIN(ret, put_bits_left(&pb));
|
||||||
while (ret >= 32) {
|
while (ret >= 32) {
|
||||||
put_bits32(&pb, get_bits_long(&gb, 32));
|
put_bits32(&pb, get_bits_long(&gb, 32));
|
||||||
ret -= 32;
|
ret -= 32;
|
||||||
@ -317,9 +320,10 @@ static int update_extradata(AVCodecParameters *codecpar)
|
|||||||
}
|
}
|
||||||
case AV_CODEC_ID_FLAC: {
|
case AV_CODEC_ID_FLAC: {
|
||||||
uint8_t buf[13];
|
uint8_t buf[13];
|
||||||
|
int size = FFMIN(codecpar->extradata_size, sizeof(buf));
|
||||||
|
|
||||||
init_put_bits(&pb, buf, sizeof(buf));
|
init_put_bits(&pb, buf, sizeof(buf));
|
||||||
ret = init_get_bits8(&gb, codecpar->extradata, codecpar->extradata_size);
|
ret = init_get_bits8(&gb, codecpar->extradata, size);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
@ -328,11 +332,14 @@ static int update_extradata(AVCodecParameters *codecpar)
|
|||||||
put_bits(&pb, 20, get_bits(&gb, 20)); // samplerate
|
put_bits(&pb, 20, get_bits(&gb, 20)); // samplerate
|
||||||
skip_bits(&gb, 3);
|
skip_bits(&gb, 3);
|
||||||
put_bits(&pb, 3, codecpar->ch_layout.nb_channels - 1);
|
put_bits(&pb, 3, codecpar->ch_layout.nb_channels - 1);
|
||||||
ret = put_bits_left(&pb);
|
ret = get_bits_left(&gb);
|
||||||
|
if (ret < 0)
|
||||||
|
return AVERROR_INVALIDDATA;
|
||||||
|
ret = FFMIN(ret, put_bits_left(&pb));
|
||||||
put_bits(&pb, ret, get_bits(&gb, ret));
|
put_bits(&pb, ret, get_bits(&gb, ret));
|
||||||
flush_put_bits(&pb);
|
flush_put_bits(&pb);
|
||||||
|
|
||||||
memcpy(codecpar->extradata, buf, sizeof(buf));
|
memcpy(codecpar->extradata, buf, put_bytes_output(&pb));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user