X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=aac_afh.c;h=c4301a2f178257b19d56b3cf297da3e1eaff337c;hb=9055c71be97f1095dcdbd83da305b600f204f763;hp=7be441ab209b5ee7ca85c371f229f0c76ece96cb;hpb=945502385e8261d6921c7e1748fa64f34b7b81fd;p=paraslash.git diff --git a/aac_afh.c b/aac_afh.c index 7be441ab..c4301a2f 100644 --- a/aac_afh.c +++ b/aac_afh.c @@ -59,7 +59,7 @@ static off_t aac_afh_seek_cb(void *user_data, off_t offset, int whence) static int aac_afh_open(const void *map, size_t mapsize, void **afh_context) { int ret; - struct aac_afh_context *c = para_malloc(sizeof(*c)); + struct aac_afh_context *c = alloc(sizeof(*c)); c->map = map; c->mapsize = mapsize; @@ -101,7 +101,8 @@ static int aac_afh_get_chunk(uint32_t chunk_num, void *afh_context, ret = mp4_get_sample_size(c->mp4, chunk_num, &ss); if (ret < 0) return ret; - assert(ss + offset <= c->mapsize); + if (ss + offset > c->mapsize) /* file got truncated?! */ + return -E_MP4_CORRUPT; *buf = c->map + offset; *len = ss; return 1; @@ -141,18 +142,21 @@ static int aac_get_file_info(char *map, size_t numbytes, __a_unused int fd, afhi->max_chunk_size = 0; for (n = 0; n < afhi->chunks_total; n++) { - if (aac_afh_get_chunk(n, c, &buf, &len) < 0) - break; + ret = aac_afh_get_chunk(n, c, &buf, &len); + if (ret < 0) + goto out; afhi->max_chunk_size = PARA_MAX(afhi->max_chunk_size, len); } milliseconds = mp4_get_duration(c->mp4); afhi->seconds_total = milliseconds / 1000; ms2tv(milliseconds / afhi->chunks_total, &afhi->chunk_tv); - if (aac_afh_get_chunk(0, c, &buf, &len) >= 0) - numbytes -= buf - map; + if (aac_afh_get_chunk(0, c, &buf, &len) < 0) + goto out; + numbytes -= buf - map; afhi->bitrate = 8 * numbytes / afhi->seconds_total / 1000; aac_afh_get_taginfo(c->mp4, &afhi->tags); ret = 1; +out: aac_afh_close(c); return ret; }