Commit Graph

30 Commits

Author SHA1 Message Date
Hans Kristian Rosbach
2890c0e380 In test_deflate_copy(), we free the original struct but forget to free the copy stuct.
Found by msan.
2019-09-19 21:02:20 +02:00
Nathan Moinvaziri
b080dd07b6 Fixed several warnings in example and fuzzers. #409 2019-09-19 21:02:01 +02:00
jiangjufa
3a89dbfb26 Add test cases to #437 2019-09-15 14:19:01 +02:00
Ilya Leoshkevich
b927c6ab87 Add two new public zng_deflate{Set,Get}Params() functions
These functions allow zlib-ng callers to modify and query the
compression parameters in a future-proof way. When the caller requests a
parameter, which is not supported by the current zlib-ng version, this
situation is detected and reported to the caller. The caller may modify
or query multiple parameters at once. Currently only "level" and
"strategy" parameters are supported. It is planned to add a
"reproducible" parameter, which would affect whether IBM Z DEFLATE
CONVERSION CALL is used.

Passing enum and void * buffer was chosen over passing strings, because
of simplicity for the caller. If strings were used, C callers would have
to call snprintf() and strtoul() for setting and getting integer-valued
parameters respectively, which is quite tedious.

Bulk updates were chosen over updating individual parameters separately,
because it might make sense to apply some parameters atomically, e.g.
level and strategy.

The new functions are defined only for zlib-ng, but not compat zlib.
2019-07-18 13:19:09 +02:00
Nathan Moinvaziri
553761a51f Remove duplicate gz functions in test code (#348)
Change CMakeLists.txt so that if WITH_GZFILEOP is OFF, gz* sources are still compiled against the tests which need them.
Remove duplicate gz functions from test code.
Always compile with gz functions when zlib tests enabled in makefile.
2019-06-22 09:25:39 +02:00
Ilya Leoshkevich
3714bcf395 Fix building with gcc 8.2.1 and -Wall -Wextra -pedantic -Werror
* ptrdiff_t check always failed because of unused parameter
* sizeof(void *) check always failed because of double semicolon
* Sign issue in nice_match assignment
* dist parameter of set_bytes may be unused
* Parameters of main may be unused in test/example.c
* snprintf requires a _POSIX_C_SOURCE #define in test/minigzip.c,
  because a _POSIX_SOURCE #define is present
2019-03-27 13:01:02 +01:00
Sebastian Pop
a346a9fb77 fix bug #289: use strcpy instead of strncpy
to avoid a GCC 8 warning:

test/example.c:465:48: warning: argument to ‘sizeof’ in ‘strncpy’ call is the same expression as the source; did you mean to use the size of the destination? [-Wsizeof-pointer-memaccess]
     strncpy((char*)uncompr, garbage_str, sizeof(garbage_str));
2019-01-24 12:50:49 +01:00
Sebastian Pop
06bd4c8b10 fix several memory sanitizer errors on aarch64
With this patch we have a clean run of make test on aarch64 when zlib-ng is
configured with --with-msan --with-fuzzers.
2019-01-10 09:44:58 +01:00
Sebastian Pop
6d084c10fb Fix test/example.c when compiled with ASAN
Before this patch

cmake -DWITH_SANITIZERS=1
make
make test

used to fail with:

Running tests...
Test project /home/hansr/github/zlib/zlib-ng
    Start 1: example
1/2 Test #1: example ..........................***Failed    0.14 sec
    Start 2: example64
2/2 Test #2: example64 ........................***Failed    0.13 sec

==11605==ERROR: AddressSanitizer: memcpy-param-overlap: memory ranges [0x62e000000595,0x62e0000053b5) and [0x62e000000400, 0x62e000005220) overlap
    #0 0x7fab3bcc9662 in __asan_memcpy (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x8c662)
    #1 0x40f936 in memcpy /usr/include/x86_64-linux-gnu/bits/string3.h:53
    #2 0x40f936 in read_buf /home/spop/s/zlib-ng/deflate.c:1122
    #3 0x410458 in deflate_stored /home/spop/s/zlib-ng/deflate.c:1394
    #4 0x4133d7 in zng_deflate /home/spop/s/zlib-ng/deflate.c:945
    #5 0x402253 in test_large_deflate /home/spop/s/zlib-ng/test/example.c:275
    #6 0x4014e8 in main /home/spop/s/zlib-ng/test/example.c:536
    #7 0x7fab3b89382f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
    #8 0x4018e8 in _start (/work/spop/zlib-ng/example+0x4018e8)

0x62e000000595 is located 405 bytes inside of 40000-byte region [0x62e000000400,0x62e00000a040)
allocated by thread T0 here:
    #0 0x7fab3bcd579a in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x9879a)
    #1 0x40147a in main /home/spop/s/zlib-ng/test/example.c:516

0x62e000000400 is located 0 bytes inside of 40000-byte region [0x62e000000400,0x62e00000a040)
allocated by thread T0 here:
    #0 0x7fab3bcd579a in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x9879a)
    #1 0x40147a in main /home/spop/s/zlib-ng/test/example.c:516

SUMMARY: AddressSanitizer: memcpy-param-overlap ??:0 __asan_memcpy
==11605==ABORTING

fix bug #183 following recommendations of Mika Lindqvist

 > the problem is in line c_stream.avail_in = (unsigned int)comprLen/2;
 > which feeds it too much data ... it should cap it to
 > c_stream.next_out - compr instead.
2018-11-07 10:02:46 +01:00
Mika Lindqvist
df1fd1567f Move private defines from zconf.h and zconf-ng.h to zbuild.h
* move definition of z_size_t to zbuild.h
2018-03-22 10:18:27 +01:00
Mika Lindqvist
ec6adfbfb0 [MSVC] Fix size_t/ssize_t when using ZLIB_COMPAT. (#161)
* zconf.h.in wasn't including Windows.h, that is correct header to include definitions from BaseTsd.h, and such missing required type definition for ssize_t when compiling using MS Visual C++
* Various places need implicit casting to z_size_t to get around compatibility issues, this will truncate the result when ZLIB_COMPAT is defined, calling code should check for truncation.
* Add ZLIB_COMPAT flag to nmake Makefile and use it to determine correct
  filenames instead of WITH_GZFILEOP
2018-03-22 10:01:18 +01:00
Mika Lindqvist
aff0fc6e3c Adapt code to support PREFIX macros and update build scripts 2018-01-31 10:45:29 +01:00
Mika Lindqvist
ea4113f441 test/example.c: Don't mix unsigned long and size_t. 2017-02-23 09:07:41 +01:00
Mark Adler
2a51c84f6c zlib 1.2.9 2017-02-09 11:39:40 +01:00
Mark Adler
51590d4ec7 Make globals in examples local to compilation unit. 2017-02-01 12:06:30 +01:00
Mika Lindqvist
602531cf3d Replace Z_NULL with NULL. Fix incorrect uses of NULL/Z_NULL. 2017-01-31 10:53:22 +01:00
Mika Lindqvist
63523d388d Use size_t for total_in and total_out. 2015-12-14 11:00:31 +02:00
Mika Lindqvist
9c3a280877 Type cleanup. 2015-12-14 11:00:22 +02:00
Mika Lindqvist
09403c93fd Cleanup user-defined types for 'unsigned char'
* Change 'uch' to 'unsigned char'
* Change 'Byte' to 'unsigned char'
2015-05-23 01:22:20 +03:00
Hans Kristian Rosbach
10a800267d Actually set err before checking it 2015-05-22 22:04:25 +02:00
Daniel Axtens
24cfc4d7bb Kill Byte and Bytef
Signed-off-by: Daniel Axtens <dja@axtens.net>

Conflicts:
	adler32.c
	compress.c
	deflate.c
	inflate.c
	match.c
	test/example.c
	uncompr.c
	zlib.h
2015-05-17 18:11:59 +02:00
Daniel Axtens
48f9b2a0e9 z_const -> const
Signed-off-by: Daniel Axtens <dja@axtens.net>

Conflicts:
	arch/x86/crc_folding.c
	crc32.c
2015-05-13 14:18:18 +02:00
Hans Kristian Rosbach
b3dca09caf Remove support for compiling with Z_SOLO.
Make compiling without gzip file operation support the default
 (define WITH_GZFILEOP or use --zlib-compat to enable them).
Add initial support for compiling in a zlib-compatible mode, this currently only
 enables gzip file operations and sets the ZLIB_COMPAT flag.

Conflicts:
	test/minigzip.c
2015-05-12 11:26:30 +02:00
Hans Kristian Rosbach
e5ee314ad4 Cleanup: Replace 'voidp' with 'void *' 2015-04-26 21:08:25 +02:00
hansr
84002037ee Rewrite K&R-style function prototypes to ANSI-C-style.
Only internal functions, no exported functions in this commit.
2014-10-18 22:49:16 +02:00
hansr
8999d0a963 Remove FAR variants of voidpf
And a few Bytef leftovers from test/example.c
2014-10-18 12:11:48 +02:00
hansr
3f8e26e0b7 Remove workarounds for non-ANSI-C compatible compilers (Part 2)
-Removing usage of OF() definition
2014-10-12 22:57:27 +02:00
hansr
f7e1e0130f Remove workarounds for non-ANSI-C compatible compilers (Part 1) 2014-10-12 12:38:06 +02:00
Mark Adler
62d6112a79 Clean up the usage of z_const and respect const usage within zlib.
This patch allows zlib to compile cleanly with the -Wcast-qual gcc
warning enabled, but only if ZLIB_CONST is defined, which adds
const to next_in and msg in z_stream and in the in_func prototype.
A --const option is added to ./configure which adds -DZLIB_CONST
to the compile flags, and adds -Wcast-qual to the compile flags
when ZLIBGCCWARN is set in the environment.
2012-08-13 00:02:40 -07:00
Mark Adler
1b57de3aef Move example.c and minigzip.c to test/. 2011-11-27 14:15:32 -08:00