GNOME Bugzilla – Bug 157275
[PATCH] gnome_vfs_read_entire_file hangs on gzip methods
Last modified: 2004-12-22 21:47:04 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.
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.
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).
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).
Is this ok to commit ?
Yup, make sure to commit to both HEAD and the gnome-2-8 branch.
Committed.