From c2d76f38ff3deb45d6eb859a562e26fae4f9759d Mon Sep 17 00:00:00 2001 From: Jacob Boerema Date: Tue, 24 Oct 2023 17:31:47 -0400 Subject: [PATCH] plug-ins: handle fill layers with negative height As mentioned on Discourse here https://discourse.gnome.org/t/error-opening-psd-image-height-no-support-or-invalid-1/17743 When opening a certain psd (https://github.com/Squirtleiscool/Coalition-Technologies-Skill-Test/blob/master/CT_SkillTest_v1.psd) We get a warning when creating a layer with a height of -1. Apparently certain fill layers can have a negative height. Data on how to handle this height is probably inside the 'SoCo' layer resource that we don't handle yet. For now, we will set the layer to empty and the height to 1. To be on the safe side, let's also check the layer width to be non negative. --- plug-ins/file-psd/psd-load.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/plug-ins/file-psd/psd-load.c b/plug-ins/file-psd/psd-load.c index d066448012..d015cfe857 100644 --- a/plug-ins/file-psd/psd-load.c +++ b/plug-ins/file-psd/psd-load.c @@ -2222,6 +2222,22 @@ add_layers (GimpImage *image, l_y = lyr_a[lidx]->top; l_w = lyr_a[lidx]->right - lyr_a[lidx]->left; l_h = lyr_a[lidx]->bottom - lyr_a[lidx]->top; + + if (l_h <= 0) + { + /* For fill layers this can be -1 apparently; + e.g. test file CT_SkillTest_v1.psd + Mark as empty and set height to 1. + */ + empty = TRUE; + l_h = 1; + } + if (l_w <= 0) + { + g_warning ("Unexpected layer width: %d", l_w); + empty = TRUE; + l_w = 1; + } } image_type = get_gimp_image_type (img_a->base_type, TRUE);