Skip to content

Commit

Permalink
prevent to access heap overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
knok committed Jul 24, 2019
1 parent 2df6437 commit 614e761
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/fromsixel.c
Expand Up @@ -884,7 +884,10 @@ sixel_decode_raw(
}

*ncolors = image.ncolors + 1;
*palette = (unsigned char *)sixel_allocator_malloc(allocator, (size_t)(*ncolors * 3));
int alloc_size = *ncolors;
if (alloc_size < 256) // memory access range should be 0 <= 255 (in write_png_to_file)
alloc_size = 256;
*palette = (unsigned char *)sixel_allocator_malloc(allocator, (size_t)(alloc_size * 3));
if (palette == NULL) {
sixel_allocator_free(allocator, image.data);
sixel_helper_set_additional_message(
Expand Down

0 comments on commit 614e761

Please sign in to comment.