-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gzseek broken on uncompressed streams on Windows #95
Comments
use rewind if possible see madler/zlib#95
Additional info:
|
use rewind if possible see madler/zlib#95
Thank you for the report. I don't have a Windows system to test this on. Perhaps you can help. The difference in this case is that |
Sorry, I have no Windows experience whatsoever. I was made aware that there was a problem with a package I wrote and tracked it down, but that's as far as I can go on my own. I can perform specific tests if given directions though, I now have a virtual machine with Windows and the mingw compiler installed. |
I tried to reproduce that error on Win 8.1 x64 with VS 2008, 2010, 2012 and 2013 in both x86 and x64 builds, but it always works correctly. Could this be a problem with the MinGW C runtime? |
Carlo: Please let us know exactly on what compiler and in what run-time environment and operating system you see this problem. Thanks. |
The first report I had was from using the Julia GZip.jl package. This uses the precompiled dll which comes with zlib and calls the functions via dynamically loading the library and using the C ABI (reference). I'm not sure which version of Windows this was observed on (either 7 or 8), but I can investigate. Then, I was able to reproduce the problem in a Windows 7 32bit virtual machine. I observed the problem described above, then I tried compiling my own executable with mingw's gcc (version 4.8.1), this time using the zdll.lib static library, and the results are those reported above. I did not use any compilation flag. The mingw version is the latest available (0.6.2 perhaps?); I downloaded it a few days ago. I also verified that the "fix" of calling In my tests I made sure I was using the latest binaries downloaded from the zlib main site. I think the Julia executable is also cross-compiled with mingw, but I'm not sure, and I don't know if that's relevant. In case you want to try reproducing the original bug, the most straightforward way would be downloading Julia, then launching it and running:
The last command will fail with an "empty file" error. Let me know if there's any other detail I can provide. |
I was building zlib from source (v1.2.8 release from GitHub) with CMake and all the VS versions mentioned earlier, both static and dynamic libraries. I just gave the pre-compiled binaries from the zlib website a quick try in a VS2013 x86 build and now I also see that problem. The README for that binaries state that MinGW-GCC was used to build them: Since you also see the problem with your own MinGW-GCC built version, it might suggest that the problem is somewhere in the MinGW environment. Just a wild guess, though. I never used MinGW myself and have absolutely no clue about it. |
I was fighting with the same (or a very similar) problem since yesterday. I just wanted to mention that I tried the patch detailed here and it did the trick.
|
Please let me know if this commit fixes the problem. Thanks. |
Yes, using that revision my program works as expected :) |
Are you guys using outdated MinGW packages from mingw.org or the current mingw packages from mingw-w64.org ? |
Never mind, I can reproduce the problem with mingw-w64 too. |
Can you copy here the prototype of _lseeki64 from the header file? |
__MINGW_EXTENSION __int64 __cdecl _lseeki64(int _FileHandle,__int64 _Offset,int _Origin); |
gzFile_s is defined as:
so casting |
Not using |
The merged patch effectively disables 64-bit seeks when using mingw (making it use Reproducible using |
|
@madler I think Viktor makes a good point, is this what you intended? recap On Windows when mingw gcc is used So we are going to end up with is an unsigned result. C89 standard from 3.2.1.5 Usual arithmetic conversions
C99 standard from 6.3.1.8 Usual arithmetic conversions
So it seems the result would be of type _lseeki64 second param is type lseek second param is type Also it's confusing to have a type named z_off64_t that can be something less than 64 bits. If it's possible to have a |
- Define z_off64_t to __int64 instead of z_off_t (long) - Define LSEEK to _lseeki64 instead of lseek - Fix arithmetic in lseek call by casting unsigned int to __int64 madler#95 (comment)
* src/3rd/zlib/Makefile * src/3rd/zlib/zlib.diff % NO_VIZ macro not used by recent zlib code, stop defining it * define zlib macros to enable lseek64 on mingw, instead of patching zlib source code. Required since 1.2.9. Ref: madler/zlib#95 (comment)
Yes, that is a problem if the type of the second argument of |
gzseek problem with MinGW. See:madler/zlib#95 The fix is in znzlib.c: calling gzrewind before gzseek.
…er#95) * Inflate using wider loads and stores. In inflate_fast() the output pointer always has plenty of room to write. This means that so long as the target is capable, wide un-aligned loads and stores can be used to transfer several bytes at once. When the reference distance is too short simply unroll the data a little to increase the distance. Change-Id: I59854eb25d2b1e43561c8a2afaf9175bf10cf674
On Windows, when calling
gzopen
on a plain text file, reading some bytes (at least 1), then callinggzseek(f, 0L, SEEK_SET)
, all subsequentgzread
calls fail (they return0
).This does not happen when opening a compressed stream.
In contrast, calling
gzrewind(f)
(which should be equivalent to the above, according to the documentation in "zlib.h") always works. Also, on Linux and MacOSX there is no such issue.I'm using zlib 1.2.8, and Windows 7 32bit (but I believe 64bit is also affected).
Here is a simple test file which shows the problem (assuming "tst.tmp.txt" is any plain text file):
when running the code, the first while loop succeeds, then
gzseek
returns0
, and subsequentgzread
s fail. If the first while loop is omitted, the rest succeeds, but as long as a single byte is read the bug is observed.The text was updated successfully, but these errors were encountered: