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 157275 - [PATCH] gnome_vfs_read_entire_file hangs on gzip methods
[PATCH] gnome_vfs_read_entire_file hangs on gzip methods
Status: RESOLVED FIXED
Product: gnome-vfs
Classification: Deprecated
Component: File operations
cvs (head)
Other Linux
: High major
: ---
Assigned To: gnome-vfs maintainers
gnome-vfs maintainers
Depends on:
Blocks: 73409
 
 
Reported: 2004-11-03 19:56 UTC by Vincent Noel
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Vincent Noel 2004-11-03 19:56:23 UTC
When you try to use the gnome_vfs_read_entire_file function on a gzip file,
(i.e. /path/file.gz#gzip) the function just hangs there. What happens is that
gnome_vfs_read never returns GNOME_VFS_ERROR_EOF, so the reading routine never
exits and gnome-vfs reads zero-sized chunks forever.
This small patch fixes this by checking the size of the read chunks : 

Index: gnome-vfs-utils.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-utils.c,v
retrieving revision 1.87
diff -u -r1.87 gnome-vfs-utils.c
--- gnome-vfs-utils.c   28 Oct 2004 12:59:47 -0000      1.87
+++ gnome-vfs-utils.c   3 Nov 2004 19:52:31 -0000
@@ -1072,7 +1072,7 @@
                }
  
                total_bytes_read += bytes_read;
-       } while (result == GNOME_VFS_OK);
+       } while (result == GNOME_VFS_OK && bytes_read > 0);
  
        /* Close the file. */
        result = gnome_vfs_close (handle);

Of course it would be better to just fix the gzip method, but other half-broken
methods could also benefit from this patch.
Comment 1 Christophe Fergeau 2004-11-03 20:01:09 UTC
Yup, the gzip method should be fixed, since many apps have their own reading
loop and don't use read_entire_file, so will be eat too by this bug.
Comment 2 Vincent Noel 2004-11-03 20:08:13 UTC
Here is a patch for the gzip method :

Index: gzip-method.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/modules/gzip-method.c,v
retrieving revision 1.32
diff -u -r1.32 gzip-method.c
--- gzip-method.c       22 Jan 2004 12:29:10 -0000      1.32
+++ gzip-method.c       3 Nov 2004 20:06:28 -0000
@@ -621,7 +621,7 @@
        if (gzip_handle->last_z_result != Z_OK) {
                if (gzip_handle->last_z_result == Z_STREAM_END) {
                        *bytes_read = 0;
-                       return GNOME_VFS_OK;
+                       return GNOME_VFS_ERROR_EOF;
                } else
                        return result_from_z_result (gzip_handle->last_z_result);
        } else if (gzip_handle->last_vfs_result != GNOME_VFS_OK) {

But I cannot say for sure there won't be weird consequences for apps that expect
the method to work a certain way. It feels right to me though (if the last
reading was the end of the stream, return EOF).
Comment 3 Vincent Noel 2004-11-03 20:11:29 UTC
This patch fixes the gnome_vfs_read_entire_file for gzip files and must fix a
lot of other cases as well (the current gzip method NEVER returns EOF).
Comment 4 Vincent Noel 2004-11-04 15:50:32 UTC
Is this ok to commit ?
Comment 5 Christophe Fergeau 2004-11-04 16:05:12 UTC
Yup, make sure to commit to both HEAD and the gnome-2-8 branch.
Comment 6 Vincent Noel 2004-11-04 16:24:03 UTC
Committed.