GNOME Bugzilla – Bug 776516
Saving over existing GZ or BZ2 compressed files does not truncate them
Last modified: 2017-01-03 14:15:18 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.
Confirming.
Created attachment 342758 [details] 2000x2000 checkerboard XCF - compressed to about 6kB
Created attachment 342759 [details] 2000x2000 checkerboard XCF, distorted to force worse compression
Created attachment 342760 [details] 2000x2000 checkerboard XCF; original saved over distorted one Causes the mentioned "trailing foo after EOF" message in various archiving tools.
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
We g_open() the target files ourselves and can simply pass O_TRUNC, patch follows.
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(-)