After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 123321 - PSD plugin crashes importing a file
PSD plugin crashes importing a file
Status: RESOLVED FIXED
Product: GIMP
Classification: Other
Component: Plugins
git master
Other All
: Normal major
: 2.0
Assigned To: GIMP Bugs
GIMP Bugs
: 122602 130702 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2003-09-26 17:00 UTC by Jakub Steiner
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
psds.tar.bz2 (347.65 KB, application/octet-stream)
2003-09-26 17:01 UTC, Jakub Steiner
  Details
patch for passing utf8 strings (1.62 KB, patch)
2003-11-27 12:00 UTC, Adam D. Moss
none Details | Review
potential fix for crashing on 0x0 layers. Needs testing for someone who can reproduce the problem (1.76 KB, patch)
2004-01-01 08:45 UTC, Daniel Rogers
none Details | Review
New fix. (3.13 KB, patch)
2004-01-06 20:08 UTC, Adam D. Moss
none Details | Review
next version of fix (4.81 KB, patch)
2004-01-06 21:57 UTC, Adam D. Moss
none Details | Review
console output 3.13-output-release (481.35 KB, text/plain)
2004-01-06 22:16 UTC, Pav Lucistnik
  Details
console output 3.13-output-CVS (213.81 KB, text/plain)
2004-01-06 22:16 UTC, Pav Lucistnik
  Details
next next version of fix (whole plugin source) (67.68 KB, text/plain)
2004-01-06 22:34 UTC, Adam D. Moss
  Details
latest output (214.38 KB, text/plain)
2004-01-06 22:46 UTC, Pav Lucistnik
  Details

Description Jakub Steiner 2003-09-26 17:00:06 UTC
I have tested the PSD plugin with my ancient collection of PSDs. I found
some that cause problems. 

Attached is a bzip2ed tarball of two PSD files. crash.psd crashes the
plugin with the following backtrace:

/usr/lib/gimp/1.3/plug-ins/psd: fatal error: Segmentation fault
chans_to_RGBA : NULL channel - eep!/usr/lib/gimp/1.3/plug-ins/psd
(pid:30980): [E]xit, [H]alt, show [S]tack trace or [P]roceed: s
  • #0 g_on_error_stack_trace
    from /usr/lib/libglib-2.0.so.0
  • #1 g_on_error_query
    from /usr/lib/libglib-2.0.so.0
  • #2 gimp_plugin_sigfatal_handler
  • #3 <signal handler called>
  • #4 gimp_tile_ref
    at gimptile.c line 65
  • #5 gimp_pixel_rgn_set_rect
  • #6 load_image
  • #7 run
  • #8 gimp_proc_run
    at gimp.c line 1575
  • #9 gimp_loop
    at gimp.c line 1467
  • #10 gimp_main
  • #11 main
    at psd.c line 378
  • #12 __libc_start_main
    from /lib/tls/libc.so.6

The other (garbage.psd) opens up with some layers messed up.
Comment 1 Jakub Steiner 2003-09-26 17:01:35 UTC
Created attachment 20318 [details]
psds.tar.bz2
Comment 2 Maurits Rijk 2003-09-28 14:08:56 UTC
One of the problems (still looking into the details) is that the
plug-in tries to add a layer with both width and height equal to zero.
Comment 3 Maurits Rijk 2003-09-28 15:16:21 UTC
One step further: gimp_layer_new doesn't seem to like names like '...
celý clánek' very much. It returns a layer_ID of -1, which results in
a later width and height of zero, that makes the gimp_pixel_rgn_init
complain. This accounts for 2 layers in the crash.psd picture.

The second problem is that actually one of the layers has width and
height of zero. This again results in a layer_ID of -1 after a
gimp_layer_new, giving the same problems as described above.

Problem is pretty clear. Now only a good solution ;)
Comment 4 Sven Neumann 2003-09-28 15:51:38 UTC
In general all strings passed to the PDB have to be in UTF-8 encoding.
We could add a fallback that attempts to convert from the encoding of
the currently active locale to UTF-8. This is what our XCF import
already does. See bug 79897.
Comment 5 Michael Natterer 2003-09-29 00:31:35 UTC
I'd rather say the PSD plug-in should figure or at least
guess what encoding the file has and g_convert() its
strings to UTF-8 before passing them to GIMP.
Comment 6 Sven Neumann 2003-09-29 10:21:13 UTC
Sure, but I am afraid the PSD file format doesn't specify any
encoding, or does it?
Comment 7 Maurits Rijk 2003-09-29 11:56:50 UTC
I looked in the latest publically availble spec (Photoshop 6.0). It
doesn't specify encoding.
Comment 8 Sven Neumann 2003-11-25 18:24:20 UTC
Either the PSD plug-in should make use of gimp_any_to_utf8() or the
PDB wrapper should be changed to do that for all kinds of names passed
to PDB functions.

http://developer.gimp.org/api/1.3/libgimpbase/libgimpbase-gimputils.html#gimp-any-to-utf8
Comment 9 Adam D. Moss 2003-11-27 11:12:38 UTC
Okay, the non-utf8 thing is a gimp2 foible... 1.2.x doesn't care. 
I'll see if I can conconct a blind-patch.
Comment 10 Adam D. Moss 2003-11-27 11:17:21 UTC
There's nothing obviously wrong with the loaded garbage.psd in gimp
1.2.x, but then I don't know what it's supposed to look like.  It
should be a separate bug, I think.
Comment 11 Adam D. Moss 2003-11-27 12:00:24 UTC
Created attachment 21860 [details] [review]
patch for passing utf8 strings
Comment 12 Adam D. Moss 2003-11-27 12:01:49 UTC
utterly untested attachment 21860 [details] [review] should sort out the utf8 stuff.
Comment 13 Adam D. Moss 2003-11-27 13:57:38 UTC
The patch doesn't cover the genuinely-0x0-layer problem though.  I
don't think we can correctly just skip creating these layers, since
they might have other data attached to them that shouldn't just be
thrown away (at the very least the composition mode, the layer name,
etc).  GIMP 1.2.x didn't care about making 0x0 layers, it would just
not add them to the image's layer list.  GIMP 1.3.x does care.

The 0x0 layers are (very very likely) a 'real' thing rather than just
a mis-parsing of the PSD file.  Photoshop usually keeps the saved data
shrink-wrapped to the bounds of the pixels that are actually used... I
guess it was a bit zealous in this case.

Still, it wouldn't be an enormous crime to just skip the 0x0 layers.

I think the proper solution is for the PSD plugin to promote a 0x0
layer to a 1x1 layer (with alpha) with a single transparent pixel. 
Kinda hacky.  I just had a stab at doing it that way but I'm not going
to have time.  I'll see how easy it would be to just skip 0x0 layers
instead.

Comment 14 Adam D. Moss 2003-12-03 20:13:48 UTC
Can someone test the utf8 fix to check for casual regressions?  I'll
be checking in the utf8 fix soon if there are no objections.
Comment 15 Sven Neumann 2003-12-03 20:24:03 UTC
The patch looks good but I wonder what we should do about the 0x0
layers. If 1.2 accepted them, then perhaps 1.3 should allow them too.
Comment 16 Adam D. Moss 2003-12-03 23:13:28 UTC
The only reason I asked is because the UTF8 thing supposedly a real
fix for a real problem, even though it probably doesn't actually
completely fix this bug report.  That, and I'd like to move the patch
out of my local tree so I can move on to some other fixes. :)

I don't really know about the 0x0 thing.  It was probably only an
accident that 1.2 didn't quite choke on 0x0 drawables.  It may have
been design but I can't easily rationalise it.
Comment 17 Sven Neumann 2003-12-04 23:02:09 UTC
Please commit the UTF-8 fix then. That's the best way to get it tested.
Comment 18 Adam D. Moss 2003-12-04 23:25:06 UTC
I would agree, but without being able to build I can't quite guarantee
that this even compiles, though my eyes tell me it's okay.  Was hoping
to get basic confirmation before potentially breaking the tree.
Comment 19 Sven Neumann 2003-12-04 23:35:49 UTC
Well, yes it applies cleanly against CVS and compiles w/o a warning.
Comment 20 Adam D. Moss 2003-12-04 23:45:02 UTC
Yay.  UTF8 stuff now checked-in then.
Comment 21 Sven Neumann 2003-12-05 12:12:15 UTC
IIRC Potatoshop makes the user think that all layers are of image size. 
Or basically all layers are of image size but in order to reduce file
size, only the bounding box of all non-transparent pixels is saved.

Shouldn't the PSD plug-in create all layers at image size then?
Comment 22 Adam D. Moss 2003-12-05 12:41:49 UTC
I don't see a compelling reason to do so.  We're just trying to load
photoshop images, not be a photoshop emulator -- expanding every layer
unnecessarily sounds like a recipe for wasting a great deal of memory
for no particular reason.  (I'm pretty sure that internally photoshop
only keeps a sloppy bounding box of the pixels covered and we're
getting fairly straight dumps of its [historical] internal structures
in the PSD file, because nothing else about the PSD format indicates
that the format was designed for efficiency [or quality,
extensibility, flexibility, parsability, sanity].)  If the GIMP core
also wants to offer 'boundless' layers that automatically expand when
painted onto, that's its own look-out, and if people go for that
paradigm then it's going to be useful regardless of the file format
from which the image's data from originally loaded.

Comment 23 Daniel Rogers 2004-01-01 08:40:43 UTC
First off: I didn't get a crash with crash.psd, the plugin quit itself
with "layer blend signature incorrect :-(" instead of a segfault. 
This makes me think that crash.psd is corrupt.

I tried to add a continue statement to the loop that actually adds the
layers to the gimpimage.  If I could somehow get the plugin to read
the image file and crash where it crashed for the reporter I think
this would work.  I am attaching the patch.  This patch just skips the
0x0 layer (since I think this is the more correct thing to do) but it
would be fairly trivial to add a fake layer of any size at the same
point as the continue.
Comment 24 Daniel Rogers 2004-01-01 08:45:07 UTC
Created attachment 22814 [details] [review]
potential fix for crashing on 0x0 layers.  Needs testing for someone who can reproduce the problem
Comment 25 Pav Lucistnik 2004-01-06 18:56:28 UTC
This last patch fixed this assertion for me:

(psd:39846): LibGimp-CRITICAL **: file gimppixelrgn.c: line 466
(gimp_pixel_rgn_set_rect): assertion `buf != NULL' failed

But it still crashes later. (See ticket 130702).
Comment 26 Daniel Rogers 2004-01-06 19:19:13 UTC
ok.  Two things.  First, that second crash should have been reported
here, as it is the same bug.  The second crash is very confusing
because that patch has not been submitted to cvs (things don't get
submitted until they are confirmed to work).  Second, typing bug
#130702 gives us a link to that bug report.
Comment 27 Daniel Rogers 2004-01-06 19:20:56 UTC
*** Bug 130702 has been marked as a duplicate of this bug. ***
Comment 28 Daniel Rogers 2004-01-06 19:24:08 UTC
Here is the crash the reporter got after applying the patch. (taken
directly from bug #130702)

Photoshop import plugin crashes when loading certain photoshop file.

Console output:

This is a development version of The GIMP.
Debug messages may appear here.

gimp_composite: use=yes, verbose=no +mmx +sse -sse2 -3dnow -altivec -vis

(psd:39846): LibGimp-CRITICAL **: file gimppixelrgn.c: line 466
(gimp_pixel_rgn_set_rect): assertion `buf != NULL' failed

(psd:39846): LibGimp-CRITICAL **: file gimppixelrgn.c: line 89
(gimp_pixel_rgn_init): assertion `x >= 0 && x + width <= drawable->width'
failed

(psd:39846): LibGimp-CRITICAL **: file gimppixelrgn.c: line 467
(gimp_pixel_rgn_set_rect): assertion `x >= 0 && x + width <=
pr->drawable->width' failed

(psd:39846): LibGimp-CRITICAL **: file gimppixelrgn.c: line 89
(gimp_pixel_rgn_init): assertion `x >= 0 && x + width <= drawable->width'
failed
/usr/X11R6/libexec/gimp/1.3/plug-ins/psd: fatal error: Segmentation fault
chans_to_RGBA : NULL channel -
eep!/usr/X11R6/libexec/gimp/1.3/plug-ins/psd
(pid:39846): [E]xit, [H]alt, show [S]tack trace or [P]roceed: S
  • #0 g_on_error_stack_trace
  • #1 g_on_error_query
    from /usr/local/lib/libglib-2.0.so.200
  • #2 gimp_plugin_sigfatal_handler
    at gimp.c line 1412
  • #3 ??
  • #4 load_image
  • #5 run
  • #6 gimp_proc_run
    at gimp.c line 1666
  • #7 gimp_loop
    at gimp.c line 1554
  • #8 gimp_main
  • #9 main
    at psd.c line 383

Problematic file is available from http://raven.oook.cz/domenyhome.psd
GIMP was compiled with CFLAGS -O -pipe -g, stripped on instalation.


Comment 29 Adam D. Moss 2004-01-06 20:08:31 UTC
Created attachment 23027 [details] [review]
New fix.
Comment 30 Adam D. Moss 2004-01-06 20:12:14 UTC
This patch incorporates/supersedes the former patches (also removing
the 8BIM message change which is a potential crasher).  This patch
adds the 0 width/height check in (hopefully) all of the remaining
places that it matters.

It's uncompiled... let us know how it works.

Comment 31 Pav Lucistnik 2004-01-06 21:32:58 UTC
Now it does not segfault, but it don't work either:

This is a development version of The GIMP.
Debug messages may appear here.

gimp_composite: use=yes, verbose=no +mmx +sse -sse2 -3dnow -altivec -vis

(psd:87698): LibGimp-CRITICAL **: file gimppixelrgn.c: line 89
(gimp_pixel_rgn_init): assertion `x >= 0 && x + width <=
drawable->width' failed

(psd:87698): LibGimp-CRITICAL **: file gimppixelrgn.c: line 467
(gimp_pixel_rgn_set_rect): assertion `x >= 0 && x + width <=
pr->drawable->width' failed

(psd:87698): LibGimp-CRITICAL **: file gimppixelrgn.c: line 89
(gimp_pixel_rgn_init): assertion `x >= 0 && x + width <=
drawable->width' failed

(gimp-1.3:87695): Gimp-Core-CRITICAL **: file gimpdrawable.c: line 984
(gimp_drawable_data): assertion `GIMP_IS_DRAWABLE (drawable)' failed

(gimp-1.3:87695): Gimp-Plug-In-WARNING **: plug-in requested invalid
drawable (killing)

(gimp-1.3:87695): Gimp-Plug-In-WARNING **: plug_in_close: plug-in
aborted before sending its procedure return values
Comment 32 Pav Lucistnik 2004-01-06 21:42:05 UTC
Backtrace of first critical warning:

(gdb) bt
  • #0 kill
    from /lib/libc.so.5
  • #1 raise
    from /lib/libc.so.5
  • #2 abort
    from /lib/libc.so.5
  • #3 g_logv
  • #4 g_log
  • #5 gimp_pixel_rgn_init
    at gimppixelrgn.c line 90
  • #6 load_image
    at psd.c line 2003
  • #7 run
    at psd.c line 441
  • #8 gimp_proc_run
    at gimp.c line 1666
  • #9 gimp_loop
    at gimp.c line 1554
  • #10 gimp_main
    at gimp.c line 445
  • #11 main
    at psd.c line 383
  • #12 _start
    at /usr/src/lib/csu/i386-elf/crt1.c line 104

There's some stack corruption (second argument in frame #4 is bogus),
that drawable is in #5
(gdb) print *drawable
$3 = {drawable_id = -1, width = 0, height = 0, bpp = 0, ntile_rows =
0, ntile_cols = 0, tiles = 0x0, shadow_tiles = 0x0}

In frame #4 (gdb) print *pr
$1 = {data = 0x0, drawable = 0x804f020, bpp = 4, rowstride = 256, x =
0, y = 0, w = 45, h = 10, dirty = 1, shadow = 0, process_count =
134558028}

Tell me what else I can check
Comment 33 Adam D. Moss 2004-01-06 21:57:05 UTC
Created attachment 23035 [details] [review]
next version of fix
Comment 34 Adam D. Moss 2004-01-06 21:59:19 UTC
This one has a minor extra fix or two aimed at this bug, plus the
backout of a regressor from another bug.  It also turns of verbose
debugging.  It would help if you could attach the output from running
it on the problem file.  Thanks.
Comment 35 Adam D. Moss 2004-01-06 22:00:30 UTC
s/turns of/turns on/
Comment 36 Pav Lucistnik 2004-01-06 22:15:29 UTC
Still don't work, output attached - 3.13-output-release

Your patch haven't applied cleanly to 1.3.23 code, so I took psd.c
from CVS and that shows regression in handling of layer names, see
3.13-output-CVS (I took single file from CVS, could be caused by that).
Comment 37 Pav Lucistnik 2004-01-06 22:16:20 UTC
Created attachment 23036 [details]
console output 3.13-output-release
Comment 38 Pav Lucistnik 2004-01-06 22:16:48 UTC
Created attachment 23037 [details]
console output 3.13-output-CVS
Comment 39 Adam D. Moss 2004-01-06 22:22:36 UTC
In theory that's not a regression in layer names, it's the 'right'
thing to do (so I'm told :)).
Comment 40 Adam D. Moss 2004-01-06 22:34:08 UTC
Created attachment 23041 [details]
next next version of fix (whole plugin source)
Comment 41 Adam D. Moss 2004-01-06 22:35:46 UTC
Please post output with the latest attachment (which isn't a patch). 
I'm interested that there's a layer claiming to have 0 channels. 
Wonder if that's a symptom of us losing the plot in that file, or yet
another genuine photoshop mysterious shorthand for something.
Comment 42 Pav Lucistnik 2004-01-06 22:46:02 UTC
Created attachment 23042 [details]
latest output
Comment 43 Pav Lucistnik 2004-01-06 22:46:18 UTC
now it ends with layer blend signature error
Comment 44 Adam D. Moss 2004-01-06 22:48:22 UTC
Good, we're getting closer then.  I'll follow up when I next have some
spare time.
Comment 45 Adam D. Moss 2004-01-06 22:50:39 UTC
BTW, is domenyhome.psd known to be not-corrupt?  i.e. does it at least
open in photoshop?
Comment 46 Pav Lucistnik 2004-01-06 22:52:41 UTC
It opens fine with gimp-1.2.5
Comment 47 Adam D. Moss 2004-01-06 22:56:54 UTC
Yuck.  That's a bad sign.
Comment 48 Daniel Rogers 2004-01-16 16:00:32 UTC
Bad sign? Is more detail available here?  Does this spell doom for psd
support on the gimp?
Comment 49 Adam D. Moss 2004-01-16 16:06:43 UTC
No, it simply means that we have a regression, and I hate regressions.
 Comparing the debug output of the 1.2 and 1.3 plugins would probably
pinpoint the divergance quite quickly, but I don't have time at the
moment.
Comment 50 Michael Schumacher 2004-02-13 21:21:55 UTC
Both images now open fine in current CVS.
Comment 51 Michael Natterer 2004-02-13 23:05:54 UTC
Confirmed. All files attached/linked here open fine
with current CVS.
Comment 52 Michael Natterer 2004-02-13 23:23:34 UTC
*** Bug 122602 has been marked as a duplicate of this bug. ***
Comment 53 Michael Natterer 2004-02-13 23:24:14 UTC
*** Bug 122602 has been marked as a duplicate of this bug. ***