plug-ins, tga: don't crash when generating a huge amount of messages

A follow-up to the previous commits, that address the tga issues from
issue #11822.

On Windows, when using the error console for messages, a huge amount
of error messages, that can be generated with special fuzzed images,
like crash-f65fd5404bff32c1d9d10ee049d9c98d02bbbdc2.tga from
the above mentioned issue, can cause GIMP to crash.

Although this is most likely caused in the error console or its
dependencies, we should not let it cause problems here until that is
fixed. There is also no real need to generate a huge amount of similar
repeated error messages, so let's limit it to 10 per read line of input.
This commit is contained in:
Jacob Boerema 2024-07-19 14:42:17 -04:00
parent 2ba35e5b3d
commit 1f06286717
1 changed files with 17 additions and 2 deletions

View File

@ -866,14 +866,29 @@ apply_colormap (guchar *dest,
guint16 colorMapLength)
{
guint x;
gint errcnt = 0;
for (x = 0; x < width; x++)
{
guchar entryIndex = src[x] - colorMapIndex;
if (src[x] < colorMapIndex || entryIndex >= colorMapLength) {
g_message ("Unsupported colormap entry: %u",
src[x]);
/* On Windows the error console can run out of resources when
* producing a huge amount of messages. This can happen when using
* fuzzed test images. This causes unresponsiveness at first and
* finally crashes GIMP. Eventually this needs to be fixed at the
* source, but for now let's limit the error messages to 10
* per line (this function is called once per read_line). */
if (errcnt < 10)
{
g_message ("Unsupported colormap entry: %u",
src[x]);
}
else if (errcnt == 10)
{
g_message ("Too many colormap errors. Image may be corrupt.");
}
errcnt++;
entryIndex = 0;
}