From b75e2e7e6df89a773ff7f94ccef3e692a12c7306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Alfv=C3=A9n?= Date: Tue, 4 Oct 2022 08:18:44 +0200 Subject: MLBEDSW-6626: Initialize lut_val in mlw_codec The palette variable located on the stack was not properly initialized and could potentially overwrite the stack memory when palette size was increased to 2. Make sure lut value is initialized. Signed-off-by: Johan Alfven Change-Id: I9fecfe218dc39c0157d1af015e725d1e4becf2f0 --- ethosu/mlw_codec/mlw_encode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ethosu') diff --git a/ethosu/mlw_codec/mlw_encode.c b/ethosu/mlw_codec/mlw_encode.c index 02e92533..d9e16a97 100644 --- a/ethosu/mlw_codec/mlw_encode.c +++ b/ethosu/mlw_codec/mlw_encode.c @@ -271,7 +271,7 @@ static void create_palette( int freq[512], pal_cnt+=cnt; } if (i==1) - i++; // palette size of 1 is not supported, make it 2 + p->lut[i++] = 0; // palette size of 1 is not supported, make it 2 // Heuristic for when to use the palette. If more than half of the // weights are in the palette then we use it. This ensures we don't @@ -349,6 +349,7 @@ static void create_inverse_palette( palette_t *p) { int sign = val&1; int mag = val>>1; int weight = sign ? -mag : mag; + assert(weight+256 >= 0 && weight+256 < 512); if (weight+256 < 512) p->inv_lut[ weight+256 ] = i; } -- cgit v1.2.1