Commit Graph

62 Commits

Author SHA1 Message Date
Xin LI
41ed14070b Make internal functions static in the test code.
To avoid warnings when building with -Wmissing-prototypes.

madler/zlib#bd9c329c1055a9265812352655ed2eec93f36e92
2024-02-07 19:15:56 +01:00
Dimitri Papadopoulos
e841518da7 Discard trailing whitespaces 2023-08-07 08:23:52 +02:00
Mika T. Lindqvist
c970422caa Fix definition of z_size_t to match documentation of legacy zlib API. 2023-02-23 12:17:34 +01:00
Mark Adler
24d7d0d75d Have build test report library version if it doesn't match zlib.h. 2023-02-03 15:49:02 +01:00
Ilya Leoshkevich
e63f36b1cf Introduce ZLIBNG_ENABLE_TESTS
This patch adds the ability to run zlib-ng test suite against the
original zlib as follows:

    cmake -DZLIB_COMPAT=ON -DZLIBNG_ENABLE_TESTS=OFF .
    make
    LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu make test

The benefit of this is that modifications to the original zlib can be
tested with a more extensive zlib-ng's testsuite, and the assumptions
that the zlib-ng tests make can be validated against the original zlib.

In addition to a number of tests that exercise purely zlib-ng specific
API, there are a few that expect zlib-ng specific behavior from the
original zlib API:

- deflate() (obviously) emits different streams
- zlib-ng's deflatePrime() can take more than 16 bits
- zVersion() returns a different string

Adjust or disable the respective tests for ZLIBNG_ENABLE_TESTS=OFF.
2022-11-01 13:25:19 +01:00
Nathan Moinvaziri
b7192b694c Move _POSIX_C_SOURCE define before first stdlib.h include in zbuild.h for posix_memalign. 2022-01-29 17:03:22 +01:00
Hans Kristian Rosbach
839c4ec998 inttypes.h includes stdint.h, so only include one of them. 2021-12-19 15:40:19 +01:00
Nathan Moinvaziri
d87543910a Fixed inflateGetDictionary length check may include bytes added by last call to inflate. 2021-12-02 09:26:32 +01:00
Ilya Leoshkevich
4b4b8a7777 IBM Z: Do not check inflateGetDictionary() with DFLTCC
The zlib manual does not specify a strict contract for
inflateGetDictionary(), it merely says that it "Returns the sliding
dictionary being maintained by inflate", which is an implementation
detail. IBM Z inflate's behavior differs from that of software, and
may change in the future to boot.
2021-10-13 15:39:57 +02:00
Nathan Moinvaziri
92107a92d3 Use helper function for printing error and exiting in example. 2021-09-22 16:14:05 +02:00
Nathan Moinvaziri
4deaf27124 Added code coverage for inflateGetDictionary in example. 2021-09-22 16:14:05 +02:00
Nathan Moinvaziri
983df0adec Call deflateBound to calculate length with custom gzip header in example. 2021-09-22 16:14:05 +02:00
Nathan Moinvaziri
454bbf3e88 Fill out gzheader before calling deflateSetHeader for better code coverage in example. 2021-09-22 16:14:05 +02:00
Nathan Moinvaziri
857e4f1e04 Added Z_UNUSED define for ignore unused variables. 2021-06-18 09:16:44 +02:00
Hans Kristian Rosbach
74436cfb05 Open up develop branch for non-stable commits.
Replace ZLIBNG_VERNUM with a larger one with space for more accurate information.
Replace ZLIBNG_VER_SUBREVISION with ZLIBNG_VER_MODIFIED and ZLIBNG_VER_STATUS.
2021-06-12 11:41:17 +02:00
Nathan Moinvaziri
982fc99401 Fixed dereference of possibly null head variable in test_deflate_set_header.
example.c:920:16: warning: dereference of possibly-NULL ‘head’ [CWE-690] [-Wanalyzer-possible-null-dereference]

  920 |     head->text = 1;
      |     ~~~~~~~~~~~^~~
  ‘test_deflate_set_header’: event 1
    |
    |  906 |     PREFIX(gz_header) *head = calloc(1, sizeof(PREFIX(gz_header)));
    |      |                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    |      |                               |
    |      |                               (1) this call could return NULL
2020-10-09 11:19:29 +02:00
Mika Lindqvist
28e5e73f34
Reintroduce support for ZLIB_CONST in compat mode. (#704)
* Reintroduce support for ZLIB_CONST in compat mode.
2020-08-23 09:58:57 +02:00
Josh Triplett
1a46fb9ee1 Fix testsuite warnings on Windows, using PRIu64
zlib-ng already counts on inttypes.h and stdint.h, so use those to avoid
printf-related warnings by casting integer fields whose size may vary to
uint64_t and printing them that way.
2020-08-20 12:05:55 +02:00
Nathan Moinvaziri
75b3788d25 Fixed const warning in deflate prime tests.
zlib-ng.h:1726:10: note: expected ‘const uint8_t * {aka const unsigned char *}’ but argument is of type ‘const char *’
2020-07-10 15:41:41 +02:00
Nathan Moinvaziri
3efa8c2b3c Fixed integer casting and signed comparison warning in test_gzio.
example.c(199,57): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
    example.c:207:32: warning: comparison between signed and unsigned integer expressions
2020-07-01 23:06:53 +02:00
Nathan Moinvaziri
6b8b4fab47 Improve deflatePrime test by wrapping gzip header and footer around deflate stream. 2020-07-01 23:06:53 +02:00
Nathan Moinvaziri
9abe04b926 Fixed wrong size being used in calloc in test_deflate_set_header.
CID 293478 (#1 of 1): Wrong size argument (SIZEOF_MISMATCH)
    suspicious_sizeof: Passing argument 1UL to function calloc that returns a pointer of type zng_gz_header * is suspicious because a multiple of sizeof (zng_gz_header) /*80*/ is expected.
2020-06-29 17:55:51 +02:00
Nathan Moinvaziri
fe69810c26 Use standard int types in zlib-ng api. 2020-06-09 22:40:36 +02:00
Nathan Moinvaziri
0b39a43490 Fixed variable set but not used static analysis warning in example.
example.c:84:14: warning: variable ‘read’ set but not used [-Wunused-but-set-variable]
     int err, read;
  example.c:198:5: warning: Value stored to 'read' is never read [deadcode.DeadStores]
    read = PREFIX(gzfread)(uncompr, uncomprLen, 1, file);
2020-06-09 08:32:24 +02:00
Nathan Moinvaziri
0986eb4a41 Fixed const correctness when assigning stream next_in. 2020-05-30 21:25:18 +02:00
Nathan Moinvaziri
7d0b252ea9 Fixed casting warnings and non-standard initializer warning in example project. 2020-05-30 21:25:18 +02:00
Nathan Moinvaziri
91508297df Added additional gzio tests for improved code coverage. 2020-05-06 09:59:51 +02:00
Pavel P
762068fdc6 Remove cvs keywords 2020-03-17 15:26:47 +01:00
Nathan Moinvaziri
e0a711cdde Fixed formatting, 4 spaces for code intent, 2 spaces for preprocessor indent, initial function brace on the same line as definition, removed extraneous spaces and new lines. 2020-02-07 10:44:20 +01:00
Mark Adler
33ce336b82 Don't bother computing check value after successful inflateSync().
inflateSync() is used to skip invalid deflate data, which means
that the check value that was being computed is no longer useful.
This commit turns off the check value computation, and furthermore
allows a successful return if the compressed data terminated in a
graceful manner. This commit also fixes a bug in the case that
inflateSync() is used before a header is ever processed. In that
case, there is no knowledge of a trailer, so the remainder is
treated as raw.
2019-10-22 09:57:38 +02:00
Nathan Moinvaziri
ad4ae2013b Fixed use of uninitialized value in test_deflate_copy when deflateCopy is called. #438 2019-10-07 09:49:36 +02:00
Nathan Moinvaziri
145bd4ca8f Fixed warnings in checksum fuzzer and example. #418 2019-09-20 09:17:17 +02:00
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