From 8b0185ba8f15abb4132a755d16e2a75c148d1976 Mon Sep 17 00:00:00 2001 From: Alx Sa Date: Mon, 7 Apr 2025 18:57:31 +0000 Subject: [PATCH] tools: Don't crash when reading invalid Curves preset When reading a gimp:curves preset file, we assume that we read in at least 64 bytes for the header. If the invalid preset file is smaller than that, g_input_stream_read_all () can read it just fine but the code fails when comparing the bytes read in to the size of the header. This means that the GError object is still NULL, so g_prefix_error () has no effect - and thus the calling code crashes when it tries to get "message" from a NULL GError object. To resolve this issue, we check if error or *error are NULL. If so, we set the error with g_set_error () instead. --- app/tools/gimpcurvestool.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/tools/gimpcurvestool.c b/app/tools/gimpcurvestool.c index 23ea73bd2c..886e42d4cf 100644 --- a/app/tools/gimpcurvestool.c +++ b/app/tools/gimpcurvestool.c @@ -752,7 +752,11 @@ gimp_curves_tool_settings_import (GimpFilterTool *filter_tool, &bytes_read, NULL, error) || bytes_read != sizeof (header)) { - g_prefix_error (error, _("Could not read header: ")); + if (error && *error) + g_prefix_error (error, _("Could not read header: ")); + else + g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ, + _("Could not read header: ")); return FALSE; }