From ff65e702e6a83697b409cebd972638fa21cdf313 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Thu, 2 Apr 2026 06:14:12 +0200 Subject: [PATCH] fix(lodepng): return error when 16 bit/channel images are used (#9882) Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/libs/lodepng/lodepng.c | 4 +++ src/libs/lodepng/lv_lodepng.c | 1 + .../test_assets/test_16bit_per_channel.png | Bin 0 -> 567 bytes .../src/test_cases/libs/test_libjpeg_turbo.c | 26 ++++-------------- tests/src/test_cases/libs/test_libpng.c | 5 ++++ tests/src/test_cases/libs/test_lodepng.c | 15 ++++++++++ tests/src/test_cases/libs/test_tjpgd.c | 5 ++++ 7 files changed, 35 insertions(+), 21 deletions(-) create mode 100644 tests/src/test_assets/test_16bit_per_channel.png diff --git a/src/libs/lodepng/lodepng.c b/src/libs/lodepng/lodepng.c index 7e37636a20..b339538e53 100644 --- a/src/libs/lodepng/lodepng.c +++ b/src/libs/lodepng/lodepng.c @@ -4668,6 +4668,8 @@ unsigned lodepng_inspect(unsigned * w, unsigned * h, LodePNGState * state, if(info->filter_method != 0) CERROR_RETURN_ERROR(state->error, 33); /*error: only interlace methods 0 and 1 exist in the specification*/ if(info->interlace_method > 1) CERROR_RETURN_ERROR(state->error, 34); + /*error: bitdepths > 8 bits per channel are not supported*/ + if(info->color.bitdepth > 8) CERROR_RETURN_ERROR(state->error, 116); if(!state->decoder.ignore_crc) { unsigned CRC = lodepng_read32bitInt(&in[29]); @@ -7432,6 +7434,8 @@ const char * lodepng_error_text(unsigned code) return "sBIT chunk has wrong size for the color type of the image"; case 115: return "sBIT value out of range"; + case 116: + return "bitdepths > 8 bits per channel are not supported"; } return "unknown error code"; } diff --git a/src/libs/lodepng/lv_lodepng.c b/src/libs/lodepng/lv_lodepng.c index 4ec0b1d137..f61db5bd6f 100644 --- a/src/libs/lodepng/lv_lodepng.c +++ b/src/libs/lodepng/lv_lodepng.c @@ -246,6 +246,7 @@ static lv_draw_buf_t * decode_png_data(const void * png_data, size_t png_data_si /*Decode the image in ARGB8888 */ unsigned error = lodepng_decode32((unsigned char **)&decoded, &png_width, &png_height, png_data, png_data_size); if(error) { + LV_LOG_WARN("error %u: %s", error, lodepng_error_text(error)); if(decoded != NULL) lv_draw_buf_destroy(decoded); return NULL; } diff --git a/tests/src/test_assets/test_16bit_per_channel.png b/tests/src/test_assets/test_16bit_per_channel.png new file mode 100644 index 0000000000000000000000000000000000000000..2a9c9587b2cbccdc9bcbbfd323a76dced5190f29 GIT binary patch literal 567 zcmeAS@N?(olHy`uVBq!ia0vp^3Lq@N1|*eVE!z&_Bzpw;GB8xBF)%c=FfjZA3N^f7 zU???UV0e|lz+g3lfkC`r&aOZkpaffzx4X-KFyM^%eg`O`TH+c}l9E`GYL#4+3Zxi} z42;Zl4UBaS%|Z+(Yh}=?IYq@@<*7DfrAzq~t8+81xPfb1Hs&F8&;MMY7VH;Bu zQno34*v!~2V!G)4TIH`9x3@I5U%At9CEmtN`ApyW3x&tR)-<<;p7LIGzU90j^Q&J~ z!Rs5+9M)a1