From ef7d6009b4f8b2e64d6ced27bc97aad0b520271e Mon Sep 17 00:00:00 2001 From: "roman.artiukhin" Date: Mon, 18 Sep 2023 13:17:11 +0300 Subject: 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 --- lib/rbcodec/codecs/libm4a/m4a.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'lib/rbcodec/codecs/libm4a/m4a.c') 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; inum_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 -- cgit v1.2.3