From 77fb0f912d578a361af76be7c74460a56309179c Mon Sep 17 00:00:00 2001 From: saratoga Date: Mon, 14 Dec 2009 01:09:01 +0000 Subject: [PATCH] Commit both patches in FS#10833 - Protect against division by zero in AAC (mp4) codec by Juliusz Chroboczek. Adds some return value checking so that faad errors don't crash rockbox when decoding broken or unsupported files. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23983 a1c6a512-1295-4272-9138-f99709370657 --- apps/codecs/aac.c | 10 +++++----- apps/codecs/libm4a/m4a.c | 3 ++- docs/CREDITS | 1 + 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/codecs/aac.c b/apps/codecs/aac.c index 60460355d..7d706f4fd 100644 --- a/apps/codecs/aac.c +++ b/apps/codecs/aac.c @@ -53,6 +53,7 @@ enum codec_status codec_main(void) int err; uint32_t s = 0; unsigned char c = 0; + void *ret; /* Generic codec initialisation */ ci->configure(DSP_SET_STEREO_MODE, STEREO_NONINTERLEAVED); @@ -179,11 +180,10 @@ next_track: buffer=ci->request_buffer(&n,sample_byte_size); /* Decode one block - returned samples will be host-endian */ - NeAACDecDecode(decoder, &frame_info, buffer, n); - /* Ignore return value, we access samples in the decoder struct - * directly. - */ - if (frame_info.error > 0) { + ret = NeAACDecDecode(decoder, &frame_info, buffer, n); + + /* NeAACDecDecode may sometimes return NULL without setting error. */ + if (ret == NULL || frame_info.error > 0) { LOGF("FAAD: decode error '%s'\n", NeAACDecGetErrorMessage(frame_info.error)); err = CODEC_ERROR; goto done; diff --git a/apps/codecs/libm4a/m4a.c b/apps/codecs/libm4a/m4a.c index f0666403e..92e619db3 100644 --- a/apps/codecs/libm4a/m4a.c +++ b/apps/codecs/libm4a/m4a.c @@ -194,7 +194,8 @@ unsigned int get_sample_offset(demux_res_t *demux_res, uint32_t sample) prev_chunk_samples = demux_res->sample_to_chunk[i].num_samples; } - if (sample >= demux_res->sample_to_chunk[0].num_samples) + if (prev_chunk_samples > 0 && + sample >= demux_res->sample_to_chunk[0].num_samples) { chunk = prev_chunk + (sample - total_samples) / prev_chunk_samples; } diff --git a/docs/CREDITS b/docs/CREDITS index 0eddfbef4..23fe2ee29 100644 --- a/docs/CREDITS +++ b/docs/CREDITS @@ -508,6 +508,7 @@ Simon Rothen Pavel Rzehák Diego Herranz Viktor Varga +Juliusz Chroboczek The libmad team The wavpack team -- 2.11.4.GIT