From 1c730905ec8adbcce7bf85658c80941c9536926a Mon Sep 17 00:00:00 2001 From: Philippe G Date: Wed, 23 Dec 2020 00:55:21 -0800 Subject: [PATCH] mp4/aac decoder might overflow and lock at the end of track - release --- components/squeezelite/helix-aac.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/components/squeezelite/helix-aac.c b/components/squeezelite/helix-aac.c index 24296d89..457fd6c3 100644 --- a/components/squeezelite/helix-aac.c +++ b/components/squeezelite/helix-aac.c @@ -430,14 +430,20 @@ static decode_state helixaac_decode(void) { } } - // we always have at least WRAPBUF_LEN unless it's the end of a stream + // we always have at least WRAPBUF_LEN unless it's the end of a stream + /* There is a bug in helixaac where it overflows its buffer when not having + * samples and enters an infinite loop so we can't do here the proper test + * if (bytes_wrap < WRAPBUF_LEN && bytes_wrap != bytes_total) + * but instead we'll zero the wrap buf and provide a safe overflow space + * for the decoder + */ if (bytes_wrap < WRAPBUF_LEN) { // build a linear buffer if we are crossing the end of streambuf memcpy(a->wrap_buf, streambuf->readp, bytes_wrap); - memcpy(a->wrap_buf + bytes_wrap, streambuf->buf, min(WRAPBUF_LEN, bytes_total) - bytes_wrap); - + memcpy(a->wrap_buf + bytes_wrap, streambuf->buf, min(WRAPBUF_LEN, bytes_total) - bytes_wrap); sptr = a->wrap_buf; - bytes = bytes_wrap = min(WRAPBUF_LEN, bytes_total); + if (bytes_total < WRAPBUF_LEN) memset(a->wrap_buf + bytes_total, 0, WRAPBUF_LEN - bytes_total); + else bytes = bytes_wrap = min(WRAPBUF_LEN, bytes_total); } else { sptr = streambuf->readp; bytes = bytes_wrap;