67 Commits

Author SHA1 Message Date
tansy
72c81b3332 programs/gzip: add support for the '-t' option (test file integrity)
The '-t' option of GNU gzip allows checking whether a gzip file is valid
without writing the data anywhere.  It's relatively straightforward to
support in libdeflate-gzip too, so add support for it.

Resolves https://github.com/ebiggers/libdeflate/issues/125

[EB - updated commit message]
2021-05-06 22:48:02 -07:00
Eric Biggers
fbada10aa9 prog_util: make it clear that posix_[fm]advise errors are ignored 2021-03-14 21:04:26 -07:00
Eric Biggers
ea2f7569b0 benchmark: clarify what the -g and -z options do
Update https://github.com/ebiggers/libdeflate/issues/120
2021-03-12 00:07:40 -08:00
Fabrice Fontaine
e1803dc145 programs/prog_util.h: include sys/types.h
Include sys/types.h to avoid the following build failure on uclibc:

In file included from programs/gzip.c:28:0:
programs/prog_util.h:159:1: error: unknown type name ‘ssize_t’
 ssize_t xread(struct file_stream *strm, void *buf, size_t count);
 ^

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2020-12-28 10:40:02 -08:00
Eric Biggers
7ba3155c17 programs: rename program_invocation_name to prog_invocation_name
Avoid confusion with the GNU extension 'program_invocation_name', which
is described by 'man 3 program_invocation_name'.  The GNU version isn't
supposed to be exposed without defining _GNU_SOURCE, which we don't in
any of the relevant files, but it's best to avoid any confusion.
2020-10-25 20:49:27 -07:00
Eric Biggers
a89aba54b7 scripts: move litrunlen overflow test into a C test program
This removes the ad-hoc "edge_case" group of tests, and it removes the
dependency on Python.
2020-10-18 15:14:15 -07:00
Eric Biggers
2cb8c2142d scripts: move detect.sh into scripts directory
This is a shell script, so move it into the scripts directory.
2020-10-18 15:14:15 -07:00
Eric Biggers
eb54d9e257 programs/test_util.c: don't be noisy about skipping perf tests 2020-10-18 15:14:15 -07:00
Eric Biggers
cda4447098 programs/test_*: remove unnecessary 'tests passed' messages 2020-10-18 15:14:15 -07:00
Eric Biggers
4c92394eaa Support level 0, "no compression"
Some users may require a valid DEFLATE, zlib, or gzip stream but know
ahead of time that particular inputs are not compressible.  zlib
supports "level 0" for this use case.  Support this in libdeflate too.

Resolves https://github.com/ebiggers/libdeflate/issues/86
2020-10-10 22:31:15 -07:00
Eric Biggers
3dfd93e365 lib, programs: include common_defs.h by relative path
It's better to use a relative path, so that people not using the
Makefile don't have to put -Icommon on their compiler command line.
2020-05-08 23:03:58 -07:00
Ingvar Stepanyan
e2d1621e42 Depend on stdint.h instead of inttypes.h
stdint.h is better compatible with freestanding support as it can be
compiled even if target platform lacks I/O capabilities.

[EB - adjusted the include locations, and avoided breaking the build
 for old MSVC versions.]
2020-04-17 22:37:31 -07:00
Eric Biggers
27d5a74f03 lib: add freestanding support
Allow building libdeflate without linking to any libc functions by using
'make FREESTANDING=1'.  When using such a library build, the user will
need to call libdeflate_set_memory_allocator() before anything else,
since malloc() and free() will be unavailable.

[Folded in fix from Ingvar Stepanyan to use -nostdlib, and made
 freestanding_tests() check that no libs are linked to.]

Update https://github.com/ebiggers/libdeflate/issues/62
2020-04-17 22:32:49 -07:00
Eric Biggers
0ded4c6f52 lib: add libdeflate_set_memory_allocator()
Add an API function to install a custom memory allocator.

Resolves https://github.com/ebiggers/libdeflate/issues/62
2020-04-17 21:28:49 -07:00
Eric Biggers
740820bd66 programs: define begin_program()
In preparation for testing freestanding library builds, make all
programs call a function begin_program().
2020-04-17 21:28:49 -07:00
Eric Biggers
c872728fc8 prog_util: remove unused tstrcpy definition 2020-04-17 21:27:56 -07:00
Eric Biggers
a735fa830f lib, programs: remove all unnecessary 'extern' keywords
'extern' on function declarations is redundant.
2020-04-17 21:27:56 -07:00
Eric Biggers
21ccbd2e2f Generalize test_zlib to test_trailing_bytes
Do the same test for DEFLATE and gzip.
2020-04-17 21:10:23 -07:00
Izumi Raine
b98f0c9be4
Add tests for libdeflate_zlib_*
Adds programs/test_zlib.c which currently does the following:
1. Create some dummy data and compress it
2. Try to decompress with libdeflate_zlib_decompress
3. Try to decompress with libdeflate_zlib_decompress, with unnecessary
   trailing bytes after the compressed data
4. Try to decompress with libdeflate_zlib_decompress_ex, with
   unnecessary trailing bytes after the compressed data

In each step, we check that we get back the original data.
2020-04-17 18:29:31 +02:00
Eric Biggers
5f3830983c Use stdcall calling convention on 32-bit Windows
Not all programming languages support the cdecl calling convention.
stdcall is what the Win32 API uses, and it seems to be the better choice
for maximum compatibility with other programming languages.

So, switch from cdecl to stdcall.

Resolves https://github.com/ebiggers/libdeflate/issues/58
2019-12-27 10:48:44 -06:00
Eric Biggers
09f14551d8 detect.sh: use -Wno-error
Don't let -Werror interfere with the feature detection.
2019-08-30 00:14:43 -05:00
Eric Biggers
0015560a82 test_slow_decompression: skip by default since it's flaky
Since this is a performance-based test, unfortunately it's always going
to be flaky, so it needs to be skipped by default.
2019-08-30 00:14:43 -05:00
Eric Biggers
8474418509 test_util: make alloc_guarded_buffer() return void
Its return value is not checked, which is a bug.  But it's a test
utility, so it's better to exit on failure instead.
2019-08-30 00:14:43 -05:00
Eric Biggers
f1e56f54b2 test_util: use MAP_ANONYMOUS instead of /dev/zero
Apparently, mmap'ing /dev/zero fails on macOS.  So contrary to the
intent, it's not actually portable.  Switch to MAP_ANONYMOUS instead,
with a fallback to MAP_ANON if it's not defined.
2019-08-30 00:14:43 -05:00
Eric Biggers
2bdbe040fe test_slow_decompression: make less flaky 2019-08-11 17:36:09 -07:00
Eric Biggers
e90463fb04 programs/gunzip: allocate at least one byte for decompressed data
libdeflate's 'gunzip' program fails if the uncompressed file size is a
nonzero multiple of 4 GiB because then the ISIZE field in the gzip file
is 0, so gunzip allocates no space for the decompressed data.  Then when
libdeflate returns LIBDEFLATE_INSUFFICIENT_SPACE, gunzip doubles the
buffer size which stays 0, causing it to report "file corrupt or too
large to be processed by this program".

While neither libdeflate nor its 'gunzip' program is designed for single
gzip streams this large anyway, this particular bug can easily be fixed
by always allocating at least one byte for the decompressed data.
2019-05-21 21:13:59 -07:00
Eric Biggers
7512dfb845 test_incomplete_codes: add another test case 2019-01-14 21:37:48 -08:00
Eric Biggers
d3878bc8ae programs: new test program - test_incomplete_codes 2018-12-28 10:25:44 -06:00
Eric Biggers
c398e237b6 programs: move output_bitstream to test_util 2018-12-28 10:25:44 -06:00
Eric Biggers
ce6a95f47b programs: add test_util
Move program utility functions that are used only by "test programs"
(i.e. not by gzip/gunzip) from prog_util.{c,h} into test_util.{c,h}.
This reduces the code that is compiled for the default build target,
which excludes the test programs.
2018-12-28 10:25:44 -06:00
Eric Biggers
a64bd1e830 lib/deflate_decompress: optimize build_decode_table() via table doubling
Another build_decode_table() optimization: rather than filling all the
entries for each codeword using strided stores, just fill one initially
and fill the rest by memcpy()s as the table is incrementally expanded.

Also make some other cleanups and small optimizations.
2018-12-27 17:10:23 -06:00
Eric Biggers
dfd839df4e test_checksums: test with guard page 2018-12-23 12:34:50 -06:00
Eric Biggers
a5a4822e2a prog_util: add guarded buffer allocator 2018-12-23 12:34:50 -06:00
Eric Biggers
57cab078f1 lib: optimize decompressing repeated static Huffman blocks
Improve libdeflate's worst-case performance decompressing malicious
DEFLATE streams by about 14x, bringing it within a factor of about 2x of
zlib, by skipping rebuilding the decode tables for the static Huffman
codes when they're already loaded into the decompressor.

This improves performance decompressing a stream of all empty static
Huffman blocks from about 0.36 MB/s to 175 MB/s, or the original
reproducer given on the Github issue from about 3.3 MB/s to 219 MB/s.
A regression test is added for these cases as well as the empty dynamic
Huffman blocks case to verify worst-case performance comparable to zlib.

Resolves https://github.com/ebiggers/libdeflate/issues/33
2018-12-23 12:03:00 -06:00
Eric Biggers
dd1c157750 prog_util: add timer_KB_per_s() 2018-12-23 12:03:00 -06:00
Eric Biggers
6c26eb18ea prog_util: add ASSERT() macro 2018-12-23 12:03:00 -06:00
Eric Biggers
bf0797e666 programs/test_checksums: test Adler-32 overflow cases 2018-02-18 23:03:26 -08:00
Eric Biggers
5a9d25a892 Support multi-member gzip files 2017-11-20 00:35:24 -08:00
Eric Biggers
1726e9e87f benchmark: make it easier to integrate other compression/decompression engines 2017-05-29 18:37:01 -07:00
Eric Biggers
8be0bbfabb gzip, gunzip: accept -n option 2016-10-23 14:13:36 -07:00
Eric Biggers
5cc0fc2bbd gzip, gunzip: add dumb support for reading from stdin
No streaming yet, but as a temporary solution just read the full file
contents.
2016-10-23 13:54:53 -07:00
Eric Biggers
3a7658d144 gzip, gunzip: avoid hanging when opening special files
This matches the behavior of GNU gzip.
2016-10-23 13:54:53 -07:00
Eric Biggers
f100a42c02 gzip, gunzip: require -f or -c to (de)compress symlink
This matches the behavior of GNU gzip.
2016-10-23 13:54:53 -07:00
Eric Biggers
e4029d1e70 gzip, gunzip: warning rather than error when output file already exists
This matches the behavior of GNU gzip.
2016-10-23 13:54:53 -07:00
Eric Biggers
618958f4dd gunzip: automatically append suffix to find input file if needed 2016-10-23 13:54:53 -07:00
Eric Biggers
f3861da7cd prog_util: use 64-bit 'struct stat' on Windows and support stat() 2016-10-23 13:54:53 -07:00
Eric Biggers
4dbc5173b6 prog_util: always use 64-bit utime() on Windows 2016-10-23 13:54:53 -07:00
Eric Biggers
e7152b4866 gzip, gunzip: forbid empty suffix
This matches the behavior of GNU gzip.
2016-10-23 13:54:52 -07:00
Eric Biggers
ed923c45d4 gzip: use success status when file already has compressed suffix
This matches the behavior of GNU gzip.
2016-10-23 13:54:52 -07:00
Eric Biggers
b620773954 gzip, gunzip: don't add dot to user-specified suffix
This matches the behavior of GNU gzip.
2016-10-23 13:54:52 -07:00