From 1092550775c464f9ae8c406786fe02115776d5c6 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Mon, 3 Jan 2022 20:10:26 +0100 Subject: [PATCH] fix(png) check png magic number to be sure it's a png image --- src/extra/libs/png/lv_png.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/extra/libs/png/lv_png.c b/src/extra/libs/png/lv_png.c index d33d276b942..0b88eb89a49 100644 --- a/src/extra/libs/png/lv_png.c +++ b/src/extra/libs/png/lv_png.c @@ -98,6 +98,8 @@ static lv_res_t decoder_info(struct _lv_img_decoder_t * decoder, const void * sr /*If it's a PNG file in a C array...*/ else if(src_type == LV_IMG_SRC_VARIABLE) { const lv_img_dsc_t * img_dsc = src; + const uint8_t magic[] = {0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a}; + if(memcmp(magic, img_dsc->data, sizeof(magic))) return LV_RES_INV; header->always_zero = 0; header->cf = img_dsc->header.cf; /*Save the color format*/ header->w = img_dsc->header.w; /*Save the color width*/