diff options
author | Dave Chapman <dave@dchapman.com> | 2007-12-01 01:01:35 +0000 |
---|---|---|
committer | Dave Chapman <dave@dchapman.com> | 2007-12-01 01:01:35 +0000 |
commit | aaacb7010fc247cfc9f16b2e3aee568f29089a22 (patch) | |
tree | 5270f80f3dbad56eba3a408bdc8b36ac7394722d /apps/codecs/libm4a | |
parent | 95c117cdb8b2db2e3b5520e9181443a7915463e7 (diff) | |
download | rockbox-aaacb7010fc247cfc9f16b2e3aee568f29089a22.tar.gz rockbox-aaacb7010fc247cfc9f16b2e3aee568f29089a22.zip |
Remove the mallocs for the codecdata in the m4a parser and assume a maximum size of 64 bytes (see comments in source). Also clean up the alac_set_info() function a little and make it alignment-safe. We still need to remove the seektable related mallocs. Please report if any AAC or ALAC files stop playing in Rockbox after this commit - but it is not expected to cause problems.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15861 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/libm4a')
-rw-r--r-- | apps/codecs/libm4a/demux.c | 23 | ||||
-rw-r--r-- | apps/codecs/libm4a/m4a.h | 15 |
2 files changed, 27 insertions, 11 deletions
diff --git a/apps/codecs/libm4a/demux.c b/apps/codecs/libm4a/demux.c index 634bb4ffca..912e7327e7 100644 --- a/apps/codecs/libm4a/demux.c +++ b/apps/codecs/libm4a/demux.c | |||
@@ -150,14 +150,15 @@ static bool read_chunk_esds(qtmovie_t *qtmovie, size_t chunk_len) | |||
150 | 150 | ||
151 | /* read length */ | 151 | /* read length */ |
152 | qtmovie->res->codecdata_len = mp4ff_read_mp4_descr_length(qtmovie->stream); | 152 | qtmovie->res->codecdata_len = mp4ff_read_mp4_descr_length(qtmovie->stream); |
153 | qtmovie->res->codecdata = malloc(qtmovie->res->codecdata_len); | 153 | if (qtmovie->res->codecdata_len > MAX_CODECDATA_SIZE) |
154 | if (qtmovie->res->codecdata) | ||
155 | { | 154 | { |
156 | stream_read(qtmovie->stream, qtmovie->res->codecdata_len, qtmovie->res->codecdata); | 155 | DEBUGF("codecdata too large (%d) in esds\n", |
157 | } else { | 156 | (int)qtmovie->res->codecdata_len); |
158 | qtmovie->res->codecdata_len = 0; | 157 | return false; |
159 | } | 158 | } |
160 | 159 | ||
160 | stream_read(qtmovie->stream, qtmovie->res->codecdata_len, qtmovie->res->codecdata); | ||
161 | |||
161 | /* will skip the remainder of the atom */ | 162 | /* will skip the remainder of the atom */ |
162 | return true; | 163 | return true; |
163 | } | 164 | } |
@@ -225,19 +226,21 @@ static bool read_chunk_stsd(qtmovie_t *qtmovie, size_t chunk_len) | |||
225 | 226 | ||
226 | /* 12 = audio format atom, 8 = padding */ | 227 | /* 12 = audio format atom, 8 = padding */ |
227 | qtmovie->res->codecdata_len = entry_remaining + 12 + 8; | 228 | qtmovie->res->codecdata_len = entry_remaining + 12 + 8; |
228 | qtmovie->res->codecdata = malloc(qtmovie->res->codecdata_len); | 229 | if (qtmovie->res->codecdata_len > MAX_CODECDATA_SIZE) |
229 | |||
230 | if (!qtmovie->res->codecdata) | ||
231 | { | 230 | { |
232 | DEBUGF("stsd too large\n"); | 231 | DEBUGF("codecdata too large (%d) in stsd\n", |
233 | return false; | 232 | (int)qtmovie->res->codecdata_len); |
234 | } | 233 | } |
235 | 234 | ||
236 | memset(qtmovie->res->codecdata, 0, qtmovie->res->codecdata_len); | 235 | memset(qtmovie->res->codecdata, 0, qtmovie->res->codecdata_len); |
237 | /* audio format atom */ | 236 | /* audio format atom */ |
237 | #if 0 | ||
238 | /* The ALAC decoder skips these bytes, so there is no need to store them, | ||
239 | and this code isn't endian/alignment safe */ | ||
238 | ((unsigned int*)qtmovie->res->codecdata)[0] = 0x0c000000; | 240 | ((unsigned int*)qtmovie->res->codecdata)[0] = 0x0c000000; |
239 | ((unsigned int*)qtmovie->res->codecdata)[1] = MAKEFOURCC('a','m','r','f'); | 241 | ((unsigned int*)qtmovie->res->codecdata)[1] = MAKEFOURCC('a','m','r','f'); |
240 | ((unsigned int*)qtmovie->res->codecdata)[2] = MAKEFOURCC('c','a','l','a'); | 242 | ((unsigned int*)qtmovie->res->codecdata)[2] = MAKEFOURCC('c','a','l','a'); |
243 | #endif | ||
241 | 244 | ||
242 | stream_read(qtmovie->stream, | 245 | stream_read(qtmovie->stream, |
243 | entry_remaining, | 246 | entry_remaining, |
diff --git a/apps/codecs/libm4a/m4a.h b/apps/codecs/libm4a/m4a.h index 401cff3b7a..a4d4dc0f79 100644 --- a/apps/codecs/libm4a/m4a.h +++ b/apps/codecs/libm4a/m4a.h | |||
@@ -23,6 +23,19 @@ | |||
23 | #include <codecs.h> | 23 | #include <codecs.h> |
24 | #include <inttypes.h> | 24 | #include <inttypes.h> |
25 | 25 | ||
26 | /* AAC codecdata appears to always be less than 8 bytes - see | ||
27 | AudioSpecificConfig2 in libfaad/mp4.c | ||
28 | |||
29 | ALAC codecdata appears to always be 44 bytes (see alac_set_info in | ||
30 | libalac/alac.c) but my test file contains 56 bytes. | ||
31 | |||
32 | So we go safe and round up to 64 bytes - if we find more than this, | ||
33 | we give an error (even though we could possibly continue), so we | ||
34 | can increase this buffer. | ||
35 | */ | ||
36 | |||
37 | #define MAX_CODECDATA_SIZE 64 | ||
38 | |||
26 | typedef struct { | 39 | typedef struct { |
27 | struct codec_api* ci; | 40 | struct codec_api* ci; |
28 | int eof; | 41 | int eof; |
@@ -57,7 +70,7 @@ typedef struct | |||
57 | uint32_t num_sample_byte_sizes; | 70 | uint32_t num_sample_byte_sizes; |
58 | 71 | ||
59 | uint32_t codecdata_len; | 72 | uint32_t codecdata_len; |
60 | void *codecdata; | 73 | uint8_t codecdata[MAX_CODECDATA_SIZE]; |
61 | 74 | ||
62 | int mdat_offset; | 75 | int mdat_offset; |
63 | uint32_t mdat_len; | 76 | uint32_t mdat_len; |