History

avformat/aiffdec: cleanup size handling for extreem cases

Michael Niedermayer committed 4 years ago

Commit c6f1e481 parent 55c605f1 file · +12 −17Browse files

Unified · Split

libavformat/aiffdec.c+12−17
@@ -54,9 +54,9 @@ static enum AVCodecID aiff_codec_get_id(int bps) · 53 unmodified lines
54}54}
55 55
56/* returns the size of the found tag */56/* returns the size of the found tag */
57static int get_tag(AVIOContext *pb, uint32_t * tag)57static int64_t get_tag(AVIOContext *pb, uint32_t * tag)
58{58{
59 int size;59 int64_t size;
60 60
61 if (avio_feof(pb))61 if (avio_feof(pb))
62 return AVERROR(EIO);62 return AVERROR(EIO);
@@ -64,16 +64,16 @@ static int get_tag(AVIOContext *pb, uint32_t * tag) · 1 unmodified line
64 *tag = avio_rl32(pb);64 *tag = avio_rl32(pb);
65 size = avio_rb32(pb);65 size = avio_rb32(pb);
66 66
67 if (size < 0)
68 size = 0x7fffffff;
69
70 return size;67 return size;
71}68}
72 69
73/* Metadata string read */70/* Metadata string read */
74static void get_meta(AVFormatContext *s, const char *key, int size)71static void get_meta(AVFormatContext *s, const char *key, int64_t size)
75{72{
76 uint8_t *str = av_malloc(size+1U);73 uint8_t *str = NULL;
74
75 if (size < SIZE_MAX)
76 str = av_malloc(size+1);
77 77
78 if (str) {78 if (str) {
79 int res = avio_read(s->pb, str, size);79 int res = avio_read(s->pb, str, size);
@@ -90,7 +90,7 @@ static void get_meta(AVFormatContext *s, const char *key, int size) · 10 unmodified lines
90}90}
91 91
92/* Returns the number of sound data frames or negative on error */92/* Returns the number of sound data frames or negative on error */
93static int get_aiff_header(AVFormatContext *s, int size,93static int get_aiff_header(AVFormatContext *s, int64_t size,
94 unsigned version)94 unsigned version)
95{95{
96 AVIOContext *pb = s->pb;96 AVIOContext *pb = s->pb;
@@ -102,9 +102,6 @@ static int get_aiff_header(AVFormatContext *s, int size, · 5 unmodified lines
102 unsigned int num_frames;102 unsigned int num_frames;
103 int channels;103 int channels;
104 104
105 if (size == INT_MAX)
106 return AVERROR_INVALIDDATA;
107
108 if (size & 1)105 if (size & 1)
109 size++;106 size++;
110 par->codec_type = AVMEDIA_TYPE_AUDIO;107 par->codec_type = AVMEDIA_TYPE_AUDIO;
@@ -216,7 +213,8 @@ static int aiff_probe(const AVProbeData *p) · 105 unmodified lines
216/* aiff input */213/* aiff input */
217static int aiff_read_header(AVFormatContext *s)214static int aiff_read_header(AVFormatContext *s)
218{215{
219 int ret, size, filesize;216 int ret;
217 int64_t filesize, size;
220 int64_t offset = 0, position;218 int64_t offset = 0, position;
221 uint32_t tag;219 uint32_t tag;
222 unsigned version = AIFF_C_VERSION1;220 unsigned version = AIFF_C_VERSION1;
@@ -227,7 +225,7 @@ static int aiff_read_header(AVFormatContext *s) · 4 unmodified lines
227 225
228 /* check FORM header */226 /* check FORM header */
229 filesize = get_tag(pb, &tag);227 filesize = get_tag(pb, &tag);
230 if (filesize < 0 || tag != MKTAG('F', 'O', 'R', 'M'))228 if (filesize < 4 || tag != MKTAG('F', 'O', 'R', 'M'))
231 return AVERROR_INVALIDDATA;229 return AVERROR_INVALIDDATA;
232 230
233 /* AIFF data type */231 /* AIFF data type */
@@ -254,10 +252,7 @@ static int aiff_read_header(AVFormatContext *s) · 20 unmodified lines
254 if (size < 0)252 if (size < 0)
255 return size;253 return size;
256 254
257 if (size >= 0x7fffffff - 8)255 filesize -= size + 8;
258 filesize = 0;
259 else
260 filesize -= size + 8;
261 256
262 switch (tag) {257 switch (tag) {
263 case MKTAG('C', 'O', 'M', 'M'): /* Common chunk */258 case MKTAG('C', 'O', 'M', 'M'): /* Common chunk */

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