From 059599fc78058dd2a964d0ff05e830638cc89202 Mon Sep 17 00:00:00 2001 From: Jacob Boerema Date: Tue, 18 Jan 2022 14:57:35 -0500 Subject: [PATCH] plug-ins: fix #6871 indexed tga file cannot be saved Exporting an image to TGA fails with a crash when it's an indexed image with alpha channel. We were not taking into account that even though the output is 1 byte per pixel, the input should allocate memory for 2 bytes per pixel (1 color index and 1 alpha channel). --- plug-ins/common/file-tga.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plug-ins/common/file-tga.c b/plug-ins/common/file-tga.c index 8a74ecc51e..7c2e7e1a7b 100644 --- a/plug-ins/common/file-tga.c +++ b/plug-ins/common/file-tga.c @@ -1353,7 +1353,10 @@ save_image (GFile *file, fputc (0, fp); } - pixels = g_new (guchar, width * out_bpp); + if (dtype == GIMP_INDEXEDA_IMAGE) + pixels = g_new (guchar, width * 2); + else + pixels = g_new (guchar, width * out_bpp); data = g_new (guchar, width * out_bpp); for (row = 0; row < height; ++row)