Commit Graph

514 Commits

Author SHA1 Message Date
Mark Adler
2556706d67 Document gzread() capability to read concurrently written files.
Also since gzread() will no longer return an error for an incomplete
gzip file, have gzclose() return an error if the last gzread() ended
in the middle of a gzip stream.
2011-12-14 04:21:00 -08:00
Mark Adler
850a198ff1 Avoid use of Z_BUF_ERROR in gz* functions except for premature EOF.
Z_BUF_ERROR was also being used for an unsuccessful gzungetc and for buffer
lengths that didn't fit in an int.  Those uses were changed to Z_DATA_ERROR
in order to assure that Z_BUF_ERROR occurs only when a premature end of
input occurs, indicating that gzclearerr() can be used.
2011-12-13 22:29:37 -08:00
Mark Adler
377173b57e Fix bug in gzread.c when end-of-file is reached. 2011-12-11 23:30:56 -08:00
Mark Adler
98f5779f42 Fix gzeof() to behave just like feof() when read is not past end of file.
Before, gzeof() would return true (accurately) when the last read request
went just up to the end of the uncompressed data.  In the analogous case,
feof() would return false, only returning true when a read request goes
past the end of the file.  This patch corrects gzeof() to behave in the
same way as feof(), as noted in the zlib.h documentation.
2011-12-11 18:22:04 -08:00
Mark Adler
70e3b1ca56 Do not set strm->adler when doing raw inflate. 2011-12-10 22:33:24 -08:00
Mark Adler
421c7a61f0 Have inflate() with Z_FINISH avoid the allocation of a window.
inflate() avoided that allocation normally, until it was modified to
update the window on a normal completion so that inflateResetKeep()
could work.  This patch restores that behavior, but only when
Z_FINISH is used successfully to complete an inflation of a stream in
a single call of inflate().  The comments in zlib.h have been updated
accordingly.
2011-12-10 22:33:24 -08:00
Mark Adler
fb00fda903 Fix gzwrite.c to accommodate reduced memory zlib compilation.
gzwrite.c had hard-coded parameters to deflateInit2() which could
contradict compile-time options for the use of less memory and fewer
code bits.  This patch suggested by Karsten Saunte fixes that.
2011-12-10 22:33:17 -08:00
Mark Adler
afe7cf78d5 Enable dictionary setting in middle of stream, and keeping the dictionary.
This patch adds the deflateResetKeep() function to retain the sliding
window for the next deflate operation, and fixes an inflateResetKeep()
problem that came from inflate() not updating the window when the
stream completed.  This enables constructing and decompressing a series
of concatenated deflate streams where each can depend on the history of
uncompressed data that precedes it.

This generalizes deflateSetDictionary() and inflateSetDictionary() to
permit setting the dictionary in the middle of a stream for raw deflate
and inflate.  This in combination with the Keep functions enables a
scheme for updating files block by block with the transmission of
compressed data, where blocks are sent with deflateResetKeep() to
retain history for better compression, and deflateSetDictionary() is
used for blocks already present at the receiver to skip compression but
insert that data in the history, again for better compression.  The
corresponding inflate calls are done on the receiver side.
2011-12-08 00:13:52 -08:00
Mark Adler
fbac04f666 Clean up infcover.c. 2011-11-30 18:19:05 -10:00
Mark Adler
014967ace3 Test the inflate code with full coverage.
Add a cover target in Makefile and the test/infcover.c test program
to cover all of the code lines in the inf*.c source files.  The
coverage is run with memory allocation checking in order to expose
memory leaks.  The coverage testing is run using:

    ./configure --cover && make cover
2011-11-27 14:15:40 -08:00
Mark Adler
de32a2d749 Remove code from inflate.c and infback.c that is impossible to execute.
During coverage testing it was discovered that these two lines could
never pull more bits, since the immediately preceding for loop assures
that all of the code's bits are already pulled.
2011-11-27 14:15:40 -08:00
Mark Adler
383d2cdab7 Simplify incomplete code table filling in inflate_table().
Due to earlier changes in the error checking in inflate_table(), the
code to fill in a table for an incomplete code handled cases that can
never actually occur.  This simplifies that code to handle the only
possible case, which is a single empty table entry for a code with
a single symbol with a length of one bit.
2011-11-27 14:15:40 -08:00
Mark Adler
1b57de3aef Move example.c and minigzip.c to test/. 2011-11-27 14:15:32 -08:00
Mark Adler
0cbad869b0 Include io.h for Turbo C / Borland C++. 2011-11-21 18:38:37 -08:00
Mark Adler
15b5671b78 Facilitate compilation with Borland C++ for pragmas and vsnprintf. 2011-11-19 13:53:26 -08:00
Mark Adler
6715208bdb Change ON macro to Z_ARG to avoid application conflicts.
Using "ON" was a dumb idea, since it is common to have macros with
names like ON and OFF.  In fact, defining the OF macro back in 1995
was a bad idea, but now we're stuck with it.  Attempts to rename OF
to something else breaks many applications.
2011-11-13 13:35:02 -08:00
Mark Adler
d169dd7300 Split off AR options in Makefile.in and configure.
Adds ARFLAGS variable for options, where AR is now just the command
name.  So now $(AR) $(ARFLAGS) is used to build the static library.
2011-11-13 13:04:26 -08:00
Mark Adler
9e50ed8ef1 Add files in contrib/minizip to aid in building libminizip.
Patch provided by Franz Schrober.
2011-11-13 12:42:47 -08:00
Mark Adler
e8576790be Note behavior of uncompress() to provide as much data as it can. 2011-10-23 12:25:55 -07:00
Mark Adler
6dbf1d1026 Add comment to gzdopen() in zlib.h to use dup() when using fileno().
A problem surfaced in a multi-threaded application where fileno() was
used to get a file descriptor from an fopen(), which was then fed to
gzdopen().  The problem occurred when the gzclose() followed by the
fclose() tried to close the same file descriptor twice.  If fclose()
were not done, there would be a memory leak.  The only way out is to
dup() the file descriptor so that gzclose() closes the duplicated
file descriptor, and fclose() closes the original file descriptor.
2011-10-20 09:07:58 -07:00
Mark Adler
5ab9f47745 Add #define ZLIB_CONST option to use const in the z_stream interface.
This permits compilers to check for the proper treatment of next_in and
msg in the z_stream structure.  This is an option instead of the default
in order to preserve backward compatibility.  Some applications make use
of the z_stream structure outside of zlib, and perform operations such
as free(strm->next_in), which would not be permitted when next_in is
const.  The #define ZLIB_CONST needs to precede the #include "zlib.h">,
in order to make next_in and msg const pointers in the z_stream type.
2011-10-18 23:05:37 -07:00
Mark Adler
5b48d061c8 Fix indentation of code in inflate.c. 2011-10-09 15:25:48 -07:00
Mark Adler
d66a307941 Add --cover option to ./configure for gcc coverage testing.
This adds the -fprofile-arcs and -ftest-coverage options when compiling
the source code for the static library.  Those same options must then be
used when linking the static library into an executable.  This updates
Makefile.in to remove and .gitignore to ignore the files generated when
testing coverage.
2011-10-09 10:25:15 -07:00
Mark Adler
1bd2fa1b24 Move example.c and minigzip.c to examples/ directory. 2011-10-09 09:50:48 -07:00
Mark Adler
77b47d55f1 Add undocumented inflateResetKeep() function for CAB file decoding.
The Microsoft CAB file format compresses each block with completed
deflate streams that depend on the sliding window history of the
previous block in order to decode.  inflateResetKeep() does what
inflateReset() does, except the sliding window history from the
previous inflate operation is retained.
2011-10-07 23:13:37 -07:00
Mark Adler
f442c1e89e Add a ./config --solo option to make zlib subset with no libary use
A common request has been the ability to compile zlib to require no
other libraries.  This --solo option provides that ability.  The price
is that the gz*, compress*, and uncompress functions are eliminated,
and that the user must provide memory allocation and free routines to
deflate and inflate when initializing.
2011-10-07 02:11:56 -07:00
Mark Adler
518ad0177a Get inffixed.h and MAKEFIXED result to match. 2011-10-05 20:32:32 -07:00
Mark Adler
af030e4273 Update python link in zlib man page. 2011-10-02 18:45:21 -07:00
Mark Adler
26a99cd895 Add a transparent write mode to gzopen() when 'T' is in the mode. 2011-10-02 13:34:29 -07:00
Mark Adler
3c9d261809 Correct documentation of gzdirect() since junk at end now ignored. 2011-10-02 12:13:50 -07:00
Mark Adler
be959acf80 Clarify how gzopen() appends in zlib.h comments. 2011-10-02 12:09:29 -07:00
Mark Adler
00c836e325 Merge vestigial vsnprintf determination from zutil.h to gzguts.h.
This also moves some of the same from zconf.h to gzguts.h. A new
function, gzflags(), was created to pass the compilation flags
related to vsnprintf usage back to zlibCompileFlags() in zutil.c.
In the process, various compiler configuration files were updated
to include gzflags(), as well as the new gzgetc_() function added
when the gzgetc() macro was introduced in a previous patch.
2011-10-02 11:15:00 -07:00
Mark Adler
0956bd23dd Update zconf.h.cmakein on make distclean. 2011-10-02 01:07:31 -07:00
Mark Adler
34538d8a93 Include zconf.h.cmakein for windows large file support. 2011-10-01 10:19:36 -07:00
Mark Adler
64eccafa78 Include zconf.h for windows large file support. 2011-10-01 10:16:04 -07:00
Tor Lillqvist
7142fcfeed Always add large file support for windows 2011-10-01 10:02:09 -07:00
Mark Adler
a4f7c65374 Update copyright dates on gz* source files. 2011-09-30 22:26:04 -07:00
Mark Adler
8768ba98af Fix gzclose() to return the actual error last encountered. 2011-09-30 22:19:12 -07:00
Mark Adler
acfc85772a Change gzgetc() to a macro for speed (~40% speedup in testing). 2011-09-26 22:50:28 -07:00
Mark Adler
8e0d212910 Simplify gzseek() now that raw after gzip is ignored. 2011-09-26 18:34:07 -07:00
Mark Adler
50e440f081 Allow gzrewind() and gzseek() after a premature end-of-file. 2011-09-26 18:20:32 -07:00
Mark Adler
5ad116abda Allow gzread() and related to continue after gzclearerr().
Before this fix, gzread() would lose data if a premature end of file
was encountered.  This prevented gzread() from being used on a file
that was being written concurrently.  Now gzread() returns all of the
data it has available before indicating a premature end of file.

This also changes the error returned on a premature end of file from
Z_DATA_ERROR to Z_BUF_ERROR.  This allows the user to determine if
the error is recoverable, which it is if Z_BUF_ERROR is returned.  If
a Z_DATA_ERROR is returned, then the error is not recoverable.

This patch replaces the functionality of a previous patch that fixed
reading through an empty gzip stream in a concatenation of gzip
streams.

To implement this fix, a noticeable rewrite of gzread.c was needed.
The patch has the added advantage of using inflate's gzip processing
instead of replicating the functionality in gzread.c.  This makes the
gz code a little simpler.
2011-09-26 00:57:26 -07:00
Mark Adler
a9ae24b653 Change gzread() and related to ignore junk after gzip streams.
Previously the new gz* functions (introduced in 1.2.4) would read and
return raw data after the last gzip stream.  This is inconsistent with
the behavior of gzip and the previous versions of zlib.  Now when one
or more gzip streams have been decoded from the file, which is then
followed by data that is not a gzip stream (as detemined by not finding
the magic header), then that subsequent trailing garbage is ignored,
and no error is returned.
2011-09-24 10:26:07 -07:00
Mark Adler
8824da8f01 Correct error in comment for gz_make(). 2011-09-24 08:33:38 -07:00
Mark Adler
0a81dc026c Fix bug in gzgets() for a concatenated empty gzip stream. 2011-09-24 00:29:46 -07:00
Mark Adler
f32370e542 Correct spelling error in gzread.c 2011-09-24 00:09:31 -07:00
Mark Adler
1f5827155d Update python link in README 2011-09-23 09:53:49 -07:00
Mark Adler
1250ac745d Add assertions to fill_window() in deflate.c to match comments. 2011-09-22 23:55:31 -07:00
Mark Adler
5cf0930ba5 Assure that high-water mark initialization is always applied in deflate. 2011-09-22 23:48:04 -07:00
Mark Adler
faa03d5141 Avoid searching past window for Z_RLE strategy.
Without this, Z_RLE could under some circumstances read one byte past
the end of the allocated sliding window. This would normally not be a
problem unless the window is right at the end of an allocated page, or
if a bounds checker is being used.
2011-09-22 23:45:00 -07:00