Patch for bug 1073308 ("ZIP ignores partially locked
files without an error message")
This patch is for zipup.c of ZIP 3.0d (beta).
zipup.c is changed to print an error message when
zread() returns -1.
If the read() function returns -1 in Win32, it's always
because of an error.
(see:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt__read.asp
"If the function tries to read at end of file, it
returns 0. If fd is invalid, or the file is not open
for reading, or the file is locked, the function
returns 1 and sets errno to EBADF.")
Problems with this patch:
1. This bug should also be fixed for other operating
systems that support partial file locking.
2. If the -q commandline option is used, the zip
program only displays "zip warning: Permission denied".
The file name and the proper error message are not
displayed.
The name of the file cannot be easily included in the
error message, because it's not available in file_read().
Logged In: YES
user_id=481420
In Linux and IEEE 1003.1 (Posix), a -1 return value from
read() also means that an error occurred (see
http://www.opengroup.org/onlinepubs/000095399/functions/read.html\).
So the same patch could be used for Linux/Unix (maybe with a
more general error message, e.g. "read error").
Logged In: YES
user_id=481420
Result of an email discussion with Greg Roelofs:
For most operating systems, zread() is mapped to read().
But for some OSs, zread() is mapped to fread():
acorn/zipup.h:#define zread(f,b,n) fread((b),1,(n),(FILE*)(f))
cmsmvs/zipup.h:#define zread(f,b,n) fread((b),1,(n),(FILE*)(f))
fread() also returns 0 on EOF. ferror() or feof() should be
used to distinguish between an error condition and EOF.
The #defines for zread() would have to be replaced by
routines that return 0 for EOF and -1 for error.
References for fread():
http://www.opengroup.org/onlinepubs/000095399/functions/fread.html
http://www.vm.ibm.com/pubs/pdf/edclv010.pdf
For VMS (and vms_native mode), zread() is mapped to vms_read:
vms/zipup.h:#define zread(f,b,n)
(vms_native?vms_read(f,b,n):fread((b),1,(n),(FILE*)(f)))
vms_read() is implemented in vms/vms_pk.c and vms/vms_im.c.
Both versions return 0 for EOF.
We can assume that zread() return 0 for EOF and -1 on error.
The best solution would be to extend file_read() to return a
completion code in addition to the length, e.g: 0=OK, 1=EOF,
2=readError, 3=interrupted.
But then mem_read would also have to be changed, because
file_read and mem_read are used with the function pointer
read_buf... It gets complicated.
An easy solution (which is not perfect) would be to replace
the line
if (len == (unsigned)EOF || len == 0) return len;
with:
if (len == 0) return 0; /* EOF */
if (len == (unsigned)-1) { /* read error */
perror("\nzip warning");
zipwarn("read error","");
return 0; }
I add another DIFF file for this OS-independent patch.
more general, OS-independent version of the patch
Logged In: YES
user_id=1172496
Originator: NO
This may be fixed in Zip 3.0f so please check the latest beta.
Logged In: YES
user_id=481420
Originator: YES
No, this bug is still open in Zip 3.0f.
see https://sourceforge.net/tracker/index.php?func=detail&aid=1073308&group_id=118012&atid=679786