Index: libgd2-2.2.5/src/gd_color_match.c =================================================================== --- libgd2-2.2.5/src/gd_color_match.c +++ libgd2-2.2.5/src/gd_color_match.c 2019-01-13 10:42:48.875452181 +0100 @@ -31,8 +31,8 @@ return -4; /* At least 1 color must be allocated */ } - buf = (unsigned long *)gdMalloc(sizeof(unsigned long) * 5 * im2->colorsTotal); - memset (buf, 0, sizeof(unsigned long) * 5 * im2->colorsTotal ); + buf = (unsigned long *)gdMalloc(sizeof(unsigned long) * 5 * gdMaxColors); + memset (buf, 0, sizeof(unsigned long) * 5 * gdMaxColors ); for (x=0; x < im1->sx; x++) { for( y=0; y<im1->sy; y++ ) {