Skip to content

Commit 614e761

Browse files
committed
prevent to access heap overflow
1 parent 2df6437 commit 614e761

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/fromsixel.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,10 @@ sixel_decode_raw(
884884
}
885885

886886
*ncolors = image.ncolors + 1;
887-
*palette = (unsigned char *)sixel_allocator_malloc(allocator, (size_t)(*ncolors * 3));
887+
int alloc_size = *ncolors;
888+
if (alloc_size < 256) // memory access range should be 0 <= 255 (in write_png_to_file)
889+
alloc_size = 256;
890+
*palette = (unsigned char *)sixel_allocator_malloc(allocator, (size_t)(alloc_size * 3));
888891
if (palette == NULL) {
889892
sixel_allocator_free(allocator, image.data);
890893
sixel_helper_set_additional_message(

0 commit comments

Comments
 (0)