Add codecov.yml file to repo, previously stored at codecov.io.
Add flags so we can distinguish between the library and the tests.
Add more detailed coverage badges to README.md.
Ilya Leoshkevich [Fri, 19 Mar 2021 21:34:32 +0000 (22:34 +0100)]
Fix MSVC warnings in deflate_quick_block_open
Add casts in order to fix the following warnings [1]:
C:\Users\Nathan\Source\zlib-ng\test\deflate_quick_block_open.c(62,69): warning C4244: '=': conversion from '__int64' to
'uint32_t', possible loss of data [C:\Users\Nathan\Source\zlib-ng\deflate_quick_block_open.vcxproj]
C:\Users\Nathan\Source\zlib-ng\test\deflate_quick_block_open.c(73,1): warning C4244: 'initializing': conversion from '_
_int64' to 'uint32_t', possible loss of data [C:\Users\Nathan\Source\zlib-ng\deflate_quick_block_open.vcxproj]
Ilya Leoshkevich [Thu, 18 Mar 2021 13:54:46 +0000 (14:54 +0100)]
Restore hash_head != 0 checks
Commit bc5915e2dec7 ("Fixed unsigned integer overflow ASAN error when
hash_head > s->strstart.") removed hash_head != 0 checks in fast,
medium and slow deflate, because it improved performance [1].
Unfortunately, the attached test started failing after that.
Apparently, as the comments suggest, the code implicitly relies on
matches with the beginning of the window being skipped. So restore the
check.
Ilya Leoshkevich [Thu, 18 Mar 2021 13:08:20 +0000 (14:08 +0100)]
Add a CMake macro for simple test executables
6 tests use the same pattern: build a binary linked with zlib-ng and
run it. At the moment this requires 5 near-identical lines of CMake
code, leading to proliferation of copy-paste. Introduce a macro to get
rid of it.
Ilya Leoshkevich [Wed, 17 Mar 2021 00:14:41 +0000 (01:14 +0100)]
Fix block_open handling in deflate_quick()
The attached test fails with "inflate() failed", because the deflate
stream that it produces ends up being corrupted. Bisect points to the
commit e7bb6db09a18 ("Replace hash_bits, hash_size and hash_mask with
defines."), but it's most likely a coincidence.
In any case, the reason is that if we happen to simultaneously exhaust
all the buffers (in, out and bi), we return finish_started without
writing the end of block symbol, which will never happen afterwards.
Fix by adding another check to the tricky condition: if we are in the
middle of a block, return need_more instead of finish_started.
DFLTCC probe points are never activated when compiling with CMake. This
is because check_include_file() only sets an internal CMake variable,
but not a C define [1].
Fix as the link suggests - by adding an explicit add_definitions.
The attached test started failing after commit ad89d5131b29 ("Don't
write end of last block when returning finish_started."): either with
"bi_buf not flushed" message in debug builds, or by producing corrupted
output in release builds.
The problem is that we must not return finish_started when bi_buf is
not empty, because the bits there will be lost. Fix by checking that
bi_valid is not 0.
Remove misleading manpage.
README.md changes:
- Added a related projects section at the end.
- Added blank line after header where missing.
- Added extra blank line before header to make them easier to spot as plain-text.
- Changed line-length for Contributing section, to make it more readable as plain-text.
Add extra space in deflate internal_state struct for future expansion.
Also make internal_state struct have a static size regardless of what features have been activated.
Internal_state is now always 6040 bytes on Linux/x86-64, and 5952 bytes on Linux/x86-32.
Disallow semantic interposition in ELF shared libraries if supported by the compiler.
This disallows calls to our own exported functions being replaced by LD_PRELOAD, thus
avoiding the potential bugs and allowing the compiler to optimize better.
Fixed ubsan error when building tree with no symbols. #782
When there are no symbols in the tree we skip build_tree calculations and emit a block using static tree with no codes.
trees.c:357:19: runtime error: unsigned integer overflow: 0 - 1 cannot be represented in type 'unsigned long'
#0 0x1000ed79b in build_tree trees.c:357
#1 0x1000ea3f5 in zng_tr_flush_block trees.c:649
#2 0x100090ab0 in deflate_slow deflate_slow.c:131
#3 0x1000572bc in zng_deflate deflate.c:990
#4 0x1000aecd3 in gz_comp gzwrite.c:125
#5 0x1000b05df in zng_gzclose_w gzwrite.c:511
#6 0x1000967a4 in zng_gzclose gzlib.c:253
#7 0x100004f70 in test_gzio example.c:133
#8 0x100010c5b in main example.c:1034
#9 0x7fff71f57cc8 in start+0x0 (libdyld.dylib:x86_64+0x1acc8)
Fixed conversion warning when assigning wsize to Pos variable.
deflate.c(218,1): warning C4244: 'initializing': conversion from 'unsigned int' to 'Pos', possible loss of data
deflate.c(241,1): warning C4244: 'initializing': conversion from 'unsigned int' to 'Pos', possible loss of data
Fixed conversion warning when calling zng_tr_tally_dist. Signature for dist and len now match zng_emit_dist.
deflate.c(1575,67): warning C4244: 'function': conversion from 'uint32_t' to 'unsigned char', possible loss of data
deflate_fast.c(60,94): warning C4244: 'function': conversion from 'uint32_t' to 'unsigned char', possible loss of data
deflate_medium.c(39,102): warning C4244: 'function': conversion from 'int' to 'unsigned char', possible loss of data
deflate_slow.c(75,101): warning C4244: 'function': conversion from 'unsigned int' to 'unsigned char', possible loss of data
Fixed str uint32_t to uint16_t casting warnings in inflate_string_tpl.h
insert_string_tpl.h(50,26): warning C4244: '=': conversion from 'const uint32_t' to 'Pos', possible loss of data
insert_string_tpl.h(67,1): warning C4244: 'initializing': conversion from 'const uint32_t' to 'Pos', possible loss of data
Fixed match_start uint32_t to uint16_t casting warnings in deflate_medium.c
deflate_medium.c(204,49): warning C4244: '=': conversion from 'unsigned int' to 'uint16_t', possible loss of data
deflate_medium.c(217,59): warning C4244: '=': conversion from 'unsigned int' to 'uint16_t', possible loss of data
deflate_medium.c(238,46): warning C4244: '=': conversion from 'unsigned int' to 'uint16_t', possible loss of data
deflate_medium.c(250,56): warning C4244: '=': conversion from 'unsigned int' to 'uint16_t', possible loss of data
Fixed ubsan warning in gzfread due to size_t overflow. #783
gzread.c:398:18: runtime error: unsigned integer overflow: 2 * 18446744073709551615 cannot be represented in type 'unsigned long'
#0 0x10009d31e in zng_gzfread gzread.c:398
#1 0x100005b1a in test_gzio example.c:213
#2 0x10001093b in main example.c:1034
#3 0x7fff71f57cc8 in start+0x0 (libdyld.dylib:x86_64+0x1acc8)
Fixed ptrdiff_t redefined static analysis warning on GCC. Failing ptrdiff_t detection due to variable unused warning combined with -Werror.
In file included from zlib-ng/zlib-ng.h:33,
from zlib-ng/zutil.h:38,
from zlib-ng/adler32.c:7:
zlib-ng/zconf-ng.h:118:18: error: conflicting types for ‘ptrdiff_t’
118 | typedef uint64_t ptrdiff_t;
| ^~~~~~~~~
In file included from zlib-ng/zutil.h:31,
from zlib-ng/adler32.c:7:
stddef.h:143:26: note: previous declaration of ‘ptrdiff_t’ was here
143 | typedef __PTRDIFF_TYPE__ ptrdiff_t;
| ^~~~~~~~~
Fix incorrect inflateSyncPoint() return value with DFLTCC
DFLTCC does not provide the necessary information to implement
inflateSyncPoint() - Incomplete-Function Status and Incomplete-Function
Length are the fields that provide the relevant information, but
unfortunately it's not enough. If DFLTCC is in use, the current code
checks software decompression state and always returns 0. This
(rightfully) confuses rsync, so fix by returning Z_STREAM_ERROR
instead.
infback.c:200:13: runtime error: left shift of 255 by 24 places cannot be represented in type 'int'
624: SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /Users/runner/work/zlib-ng/zlib-ng/infback.c:200:13 in