diff options
author | Johan Alfvén <johan.alfven@arm.com> | 2022-10-04 08:18:44 +0200 |
---|---|---|
committer | Johan Alfvén <johan.alfven@arm.com> | 2022-10-11 16:16:23 +0200 |
commit | b75e2e7e6df89a773ff7f94ccef3e692a12c7306 (patch) | |
tree | fb7301378179f0cb36a88313c2ed062f0a070d31 /ethosu/mlw_codec/mlw_encode.c | |
parent | 4a434cba156cdfb2613b7ebe4d4a4ec9f85ba616 (diff) | |
download | ethos-u-vela-b75e2e7e6df89a773ff7f94ccef3e692a12c7306.tar.gz |
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 <johan.alfven@arm.com>
Change-Id: I9fecfe218dc39c0157d1af015e725d1e4becf2f0
Diffstat (limited to 'ethosu/mlw_codec/mlw_encode.c')
-rw-r--r-- | ethosu/mlw_codec/mlw_encode.c | 3 |
1 files changed, 2 insertions, 1 deletions
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; } |