diff options
author | roman.artiukhin <bahusdrive@gmail.com> | 2023-09-18 13:17:11 +0300 |
---|---|---|
committer | Solomon Peachy <pizza@shaftnet.org> | 2023-09-19 11:13:19 -0400 |
commit | ef7d6009b4f8b2e64d6ced27bc97aad0b520271e (patch) | |
tree | 76b3d5ddc1257223fd5dcbb7169028738b577656 | |
parent | f96f7cd9419c5140bd00c85c9d3b81e1e07a1105 (diff) | |
download | rockbox-ef7d6009b4.tar.gz rockbox-ef7d6009b4.zip |
Codecs: mp4: Optimize m4a_check_sample_offset
Make optimization from 2358fabb actually work.
Fix potential out of bound access.
Remove redundant zero offset check.
Change-Id: I0a0ba04670b612d410ac17a761bd08c2915721b9
-rw-r--r-- | lib/rbcodec/codecs/aac.c | 7 | ||||
-rw-r--r-- | lib/rbcodec/codecs/libm4a/m4a.c | 15 |
2 files changed, 10 insertions, 12 deletions
diff --git a/lib/rbcodec/codecs/aac.c b/lib/rbcodec/codecs/aac.c index 8b06f5aa0e..0a4313e69e 100644 --- a/lib/rbcodec/codecs/aac.c +++ b/lib/rbcodec/codecs/aac.c @@ -202,12 +202,7 @@ enum codec_status codec_run(void) { ci->advance_buffer(file_offset - ci->curpos); } - else if (file_offset == 0) - { - LOGF("AAC: get_sample_offset error\n"); - return CODEC_ERROR; - } - + /* Request the required number of bytes from the input buffer */ buffer=ci->request_buffer(&n, FAAD_BYTE_BUFFER_SIZE); diff --git a/lib/rbcodec/codecs/libm4a/m4a.c b/lib/rbcodec/codecs/libm4a/m4a.c index 17af4cfece..958d0b1575 100644 --- a/lib/rbcodec/codecs/libm4a/m4a.c +++ b/lib/rbcodec/codecs/libm4a/m4a.c @@ -122,16 +122,19 @@ void stream_create(stream_t *stream,struct codec_api* ci) int m4a_check_sample_offset(demux_res_t *demux_res, uint32_t frame, uint32_t *start) { uint32_t i = *start; - for (i=0; i<demux_res->num_lookup_table; ++i) + for (;i < demux_res->num_lookup_table; ++i) { - if (demux_res->lookup_table[i].sample > frame || - demux_res->lookup_table[i].offset == 0) - return -1; - if (demux_res->lookup_table[i].sample == frame) + if (demux_res->lookup_table[i].sample > frame) break; + + if (demux_res->lookup_table[i].sample == frame) + { + *start = i; + return demux_res->lookup_table[i].offset; + } } *start = i; - return demux_res->lookup_table[i].offset; + return -1; } /* Seek to desired sound sample location. Return 1 on success (and modify |