History

avformat/iamf_parse: sanitize audio_roll_distance values

Ensure the values are spec complaint and that no integer overflow can happen.

James Almer committed 2 years ago

Commit 9ce065c1 parent e30bc8a1 file · +14 −2Browse files

Unified · Split

libavformat/iamf_parse.c+14−2
@@ -38,7 +38,7 @@ static int opus_decoder_config(IAMFCodecConfig *codec_config, · 37 unmodified lines
38{38{
39 int left = len - avio_tell(pb);39 int left = len - avio_tell(pb);
40 40
41 if (left < 11)41 if (left < 11 || codec_config->audio_roll_distance >= 0)
42 return AVERROR_INVALIDDATA;42 return AVERROR_INVALIDDATA;
43 43
44 codec_config->extradata = av_malloc(left + 8);44 codec_config->extradata = av_malloc(left + 8);
@@ -64,6 +64,9 @@ static int aac_decoder_config(IAMFCodecConfig *codec_config, · 19 unmodified lines
64 int object_type_id, codec_id, stream_type;64 int object_type_id, codec_id, stream_type;
65 int ret, tag, left;65 int ret, tag, left;
66 66
67 if (codec_config->audio_roll_distance >= 0)
68 return AVERROR_INVALIDDATA;
69
67 tag = avio_r8(pb);70 tag = avio_r8(pb);
68 if (tag != MP4DecConfigDescrTag)71 if (tag != MP4DecConfigDescrTag)
69 return AVERROR_INVALIDDATA;72 return AVERROR_INVALIDDATA;
@@ -118,6 +121,9 @@ static int flac_decoder_config(IAMFCodecConfig *codec_config, · 48 unmodified lines
118{121{
119 int left;122 int left;
120 123
124 if (codec_config->audio_roll_distance)
125 return AVERROR_INVALIDDATA;
126
121 avio_skip(pb, 4); // METADATA_BLOCK_HEADER127 avio_skip(pb, 4); // METADATA_BLOCK_HEADER
122 128
123 left = len - avio_tell(pb);129 left = len - avio_tell(pb);
@@ -146,7 +152,7 @@ static int ipcm_decoder_config(IAMFCodecConfig *codec_config, · 22 unmodified lines
146 };152 };
147 int sample_format = avio_r8(pb); // 0 = BE, 1 = LE153 int sample_format = avio_r8(pb); // 0 = BE, 1 = LE
148 int sample_size = (avio_r8(pb) / 8 - 2); // 16, 24, 32154 int sample_size = (avio_r8(pb) / 8 - 2); // 16, 24, 32
149 if (sample_format > 1 || sample_size > 2)155 if (sample_format > 1 || sample_size > 2 || codec_config->audio_roll_distance)
150 return AVERROR_INVALIDDATA;156 return AVERROR_INVALIDDATA;
151 157
152 codec_config->codec_id = sample_fmt[sample_format][sample_size];158 codec_config->codec_id = sample_fmt[sample_format][sample_size];
@@ -246,6 +252,12 @@ static int codec_config_obu(void *s, IAMFContext *c, AVIOContext *pb, int len) · 93 unmodified lines
246 if (ret < 0)252 if (ret < 0)
247 goto fail;253 goto fail;
248 254
255 if ((codec_config->nb_samples > INT_MAX) ||
256 (-codec_config->audio_roll_distance > INT_MAX / codec_config->nb_samples)) {
257 ret = AVERROR_INVALIDDATA;
258 goto fail;
259 }
260
249 c->codec_configs[c->nb_codec_configs++] = codec_config;261 c->codec_configs[c->nb_codec_configs++] = codec_config;
250 262
251 len -= avio_tell(pbc);263 len -= avio_tell(pbc);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t