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 776516 - Saving over existing GZ or BZ2 compressed files does not truncate them
Saving over existing GZ or BZ2 compressed files does not truncate them
Status: RESOLVED FIXED
Product: GIMP
Classification: Other
Component: Plugins
2.8.18
Other All
: Normal minor
: 2.8
Assigned To: GIMP Bugs
GIMP Bugs
Depends on:
Blocks:
 
 
Reported: 2016-12-27 00:58 UTC by Ari Pollak
Modified: 2017-01-03 14:15 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
2000x2000 checkerboard XCF - compressed to about 6kB (5.45 KB, application/x-bzip)
2017-01-03 11:56 UTC, Michael Schumacher
Details
2000x2000 checkerboard XCF, distorted to force worse compression (1.25 MB, application/x-bzip)
2017-01-03 11:57 UTC, Michael Schumacher
Details
2000x2000 checkerboard XCF; original saved over distorted one (1.25 MB, application/x-bzip)
2017-01-03 11:59 UTC, Michael Schumacher
Details

Description Ari Pollak 2016-12-27 00:58:14 UTC
From http://bugs.debian.org/849352:

It seems that saving a .xcf.bz2 file does not properly truncate it if the file
already exists. It's easy to not notice because it's only apparent if the file
should obviously be smaller than before. In my case, for example, I created a
file with many complex layers and saved it as .xcf.bz2. I then deleted all but
one simple layer and saved it, and found that the resulting filesize had not
reduced. When I tried bunzip2 on that file, it said "trailing garbage after EOF
ignored", which is what makes me believe the file was not truncated when gimp
saved it.
Comment 1 Michael Schumacher 2017-01-03 11:51:38 UTC
Confirming.
Comment 2 Michael Schumacher 2017-01-03 11:56:58 UTC
Created attachment 342758 [details]
2000x2000 checkerboard XCF - compressed to about 6kB
Comment 3 Michael Schumacher 2017-01-03 11:57:50 UTC
Created attachment 342759 [details]
2000x2000 checkerboard XCF, distorted to force worse compression
Comment 4 Michael Schumacher 2017-01-03 11:59:45 UTC
Created attachment 342760 [details]
2000x2000 checkerboard XCF; original saved over distorted one

Causes the mentioned "trailing foo after EOF" message in various archiving tools.
Comment 5 Michael Schumacher 2017-01-03 13:49:48 UTC
This happens in https://git.gnome.org/browse/gimp/tree/plug-ins/common/file-compressor.c#n765 ff.

We use BZ2_bzdopen. This is effectively the same as fdopen, and won't truncate files for mode w(b).

http://www.bzip.org/1.0.5/bzip2-manual-1.0.5.html#zlib-compat
https://linux.die.net/man/3/fdopen
Comment 6 Michael Natterer 2017-01-03 14:08:10 UTC
We g_open() the target files ourselves and can simply pass O_TRUNC,
patch follows.
Comment 7 Michael Natterer 2017-01-03 14:15:18 UTC
Fixed in master and gimp-2-8:

commit dd331a67d8552af4b52db1631c04be75075d670a
Author: Michael Natterer <mitch@gimp.org>
Date:   Tue Jan 3 15:10:35 2017 +0100

    Bug 776516 - Saving over existing GZ or BZ2 compressed files...
    
    ...does not truncate them
    
    Pass O_TRUNC to g_open() when creating the target files.
    
    (cherry picked from commit 559a75858105bdcc04f24899bba1ade79523f8ea)

 plug-ins/file-compressor/file-compressor.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)