fix(lodepng): return error when 16 bit/channel images are used (#9882)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Gabor Kiss-Vamosi
2026-04-02 06:14:12 +02:00
committed by GitHub
parent 0de4a15f52
commit ff65e702e6
7 changed files with 35 additions and 21 deletions
+4
View File
@@ -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";
}
+1
View File
@@ -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;
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 567 B

+5 -21
View File
@@ -8,6 +8,11 @@
void setUp(void)
{
/* Function run before every test */
/* Temporarily remove other JPEG decoders to make sure libjpeg is used */
lv_tjpgd_deinit();
#if LV_USE_FFMPEG
lv_ffmpeg_deinit();
#endif
}
void tearDown(void)
@@ -59,9 +64,6 @@ static void create_images(void)
void test_jpg_2(void)
{
/* Temporarily remove tjpgd decoder */
lv_tjpgd_deinit();
create_images();
TEST_ASSERT_EQUAL_SCREENSHOT("libs/jpg_2.png");
@@ -77,25 +79,16 @@ void test_jpg_2(void)
TEST_ASSERT_EQUAL_SCREENSHOT("libs/jpg_2.png");
TEST_ASSERT_MEM_LEAK_LESS_THAN(mem_before, 64);
/* Re-add tjpgd decoder */
lv_tjpgd_init();
}
void test_jpg_cmyk(void)
{
/* Temporarily remove tjpgd decoder */
lv_tjpgd_deinit();
lv_obj_clean(lv_screen_active());
lv_obj_t * img = lv_image_create(lv_screen_active());
lv_image_set_src(img, "A:src/test_assets/test_img_lvgl_logo_cmyk.jpg");
lv_obj_align(img, LV_ALIGN_CENTER, 0, 0);
TEST_ASSERT_EQUAL_SCREENSHOT("libs/jpg_cmyk.png");
/* Re-add tjpgd decoder */
lv_tjpgd_init();
}
void test_jpg_sign_error(void)
@@ -109,16 +102,10 @@ void test_jpg_sign_error(void)
lv_obj_align(img, LV_ALIGN_CENTER, 0, 0);
TEST_ASSERT_EQUAL_SCREENSHOT("libs/jpg_sign_error.png");
/* Re-add tjpgd decoder */
lv_tjpgd_init();
}
void test_jpg_decode_failed(void)
{
/* Temporarily remove tjpgd decoder */
lv_tjpgd_deinit();
lv_image_decoder_dsc_t decoder_dsc;
const char * image_path = "A:src/test_assets/test_img_lvgl_logo_with_decode_failed.jpg";
@@ -127,9 +114,6 @@ void test_jpg_decode_failed(void)
/* Should fail when decoder is removed */
TEST_ASSERT_EQUAL(LV_RESULT_INVALID, res);
/* Re-add tjpgd decoder */
lv_tjpgd_init();
}
#endif
+5
View File
@@ -8,6 +8,11 @@
void setUp(void)
{
/* Function run before every test */
/* Temporarily remove other PNG-capable decoders (lodepng/ffmpeg) to make sure libpng is used */
lv_lodepng_deinit();
#if LV_USE_FFMPEG
lv_ffmpeg_deinit();
#endif
}
void tearDown(void)
+15
View File
@@ -8,6 +8,11 @@
void setUp(void)
{
/* Function run before every test */
/* Temporarily remove other PNG decoders to make sure lodepng is used */
lv_libpng_deinit();
#if LV_USE_FFMPEG
lv_ffmpeg_deinit();
#endif
}
void tearDown(void)
@@ -76,4 +81,14 @@ void test_lodepng_1(void)
lv_libpng_init();
}
void test_lodepng_no_crash_with_16bit(void)
{
/*LodePNG should return a custom error code (116) as it's crash with 16 bit/channel images.
*(Consider upstreaming the changes)*/
lv_obj_t * img = lv_image_create(lv_screen_active());
lv_image_set_src(img, "A:src/test_assets/test_16bit_per_channel.png");
lv_refr_now(NULL);
}
#endif
+5
View File
@@ -8,6 +8,11 @@
void setUp(void)
{
/* Function run before every test */
/* Temporarily remove other JPEG decoders to make sure tjpegd is used */
lv_libjpeg_turbo_deinit();
#if LV_USE_FFMPEG
lv_ffmpeg_deinit();
#endif
}
void tearDown(void)