[gimp/gimp-2-10] app: fix #3928 GIMP cannot open .xcf
- From: Jacob Boerema <jboerema src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gimp-2-10] app: fix #3928 GIMP cannot open .xcf
- Date: Tue, 5 Apr 2022 16:27:52 +0000 (UTC)
commit e4d8a91f89c12d1985514ac563b010cf519d5828
Author: Jacob Boerema <jgboerema gmail com>
Date: Mon Apr 4 17:33:29 2022 -0400
app: fix #3928 GIMP cannot open .xcf
GIMP stopped trying to read the XCF as soon as an invalid parasite was
encountered. However, in this specific case only the parasite data is
invalid, while the rest of the image is not corrupt.
Instead of terminating when we see a corrupt parasite, we skip to the
offset after the parasite. This may still be corrupt, but we can handle
that correctly, see e.g. the XCF in bugzilla issue 685086, which was
the reason of some of the previous changes.
Additionally:
- We add some logging to make it easier to handle future issues in this
area.
- We add tests for a NULL parasite name, and for reading a different
amount of parasite data than we expected. In both cases we return
NULL instead of a parasite.
(cherry picked from commit 5b39bc963d38c8d711c79c0370514b01977fef33)
app/xcf/xcf-load.c | 37 ++++++++++++++++++++++++++++++++-----
1 file changed, 32 insertions(+), 5 deletions(-)
---
diff --git a/app/xcf/xcf-load.c b/app/xcf/xcf-load.c
index fe28d2846d..5543e57af7 100644
--- a/app/xcf/xcf-load.c
+++ b/app/xcf/xcf-load.c
@@ -1004,7 +1004,15 @@ xcf_load_image_props (XcfInfo *info,
GError *error = NULL;
if (! p)
- return FALSE;
+ {
+ gimp_message (info->gimp, G_OBJECT (info->progress),
+ GIMP_MESSAGE_WARNING,
+ "Invalid image parasite found. "
+ "Possibly corrupt XCF file.");
+
+ xcf_seek_pos (info, base + prop_size, NULL);
+ continue;
+ }
if (! gimp_image_parasite_validate (image, p, &error))
{
@@ -1840,6 +1848,8 @@ xcf_load_prop (XcfInfo *info,
if (G_UNLIKELY (xcf_read_int32 (info, (guint32 *) prop_size, 1) != 4))
return FALSE;
+ GIMP_LOG (XCF, "prop type=%d size=%u", *prop_type, *prop_size);
+
return TRUE;
}
@@ -2680,16 +2690,18 @@ xcf_load_tile_zlib (XcfInfo *info,
static GimpParasite *
xcf_load_parasite (XcfInfo *info)
{
- GimpParasite *parasite;
+ GimpParasite *parasite = NULL;
gchar *name;
guint32 flags;
- guint32 size;
+ guint32 size, size_read;
gpointer data;
xcf_read_string (info, &name, 1);
xcf_read_int32 (info, &flags, 1);
xcf_read_int32 (info, &size, 1);
+ GIMP_LOG (XCF, "Parasite name: %s, flags: %d, size: %d", name, flags, size);
+
if (size > MAX_XCF_PARASITE_DATA_LEN)
{
g_printerr ("Maximum parasite data length (%ld bytes) exceeded. "
@@ -2698,10 +2710,25 @@ xcf_load_parasite (XcfInfo *info)
return NULL;
}
+ if (!name)
+ {
+ g_printerr ("Parasite has no name! Possibly corrupt XCF file.\n");
+ return NULL;
+ }
+
data = g_new (gchar, size);
- xcf_read_int8 (info, data, size);
+ size_read = xcf_read_int8 (info, data, size);
- parasite = gimp_parasite_new (name, flags, size, data);
+ if (size_read != size)
+ {
+ g_printerr ("Incorrect parasite data size: read %u bytes instead of %u. "
+ "Possibly corrupt XCF file.\n",
+ size_read, size);
+ }
+ else
+ {
+ parasite = gimp_parasite_new (name, flags, size, data);
+ }
g_free (name);
g_free (data);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]