summaryrefslogtreecommitdiff
path: root/deflate_medium.c
AgeCommit message (Collapse)Author
2021-03-20Restore hash_head != 0 checksIlya Leoshkevich
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. [1] https://github.com/zlib-ng/zlib-ng/pull/772#issuecomment-710760300
2020-11-02Fixed casting warnings when comparing MAX_DIST.Nathan Moinvaziri
deflate_medium.c(127,76): warning C4244: '=': conversion from 'unsigned int' to 'Pos', possible loss of data
2020-11-02Fixed match_start uint32_t to uint16_t casting warnings in deflate_medium.cNathan Moinvaziri
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
2020-10-18Fixed unsigned integer overflow ASAN error when hash_head > s->strstart.Nathan Moinvaziri
zlib-ng/deflate_medium.c:244:47: runtime error: unsigned integer overflow: 58442 - 58452 cannot be represented in type 'unsigned int' Co-authored-by: Mika Lindqvist <postmaster@raasu.org> Co-authored-by: Hans Kristian Rosbach <hk-git@circlestorm.org>
2020-08-31Fix numerous sign-conversion warnings in compare256/compare258 andHans Kristian Rosbach
longest_match related code.
2020-08-31Rename ZLIB_INTERNAL to Z_INTERNAL for consistency.Nathan Moinvaziri
2020-07-03Add likely/unlikely hinting to all deflate algorithms.Hans Kristian Rosbach
2020-06-27Do not set s->prev_length in deflate_medium, it is previously set in lm_init ↵Nathan Moinvaziri
already.
2020-06-27Only set current_match to literal if hash_head == 0.Nathan Moinvaziri
2020-05-30Remove toofar checks now that we always hash 4 bytes, and the minimumHans Kristian Rosbach
match length is thus also 4. (MIN_MATCH is still 3 for other reasons)
2020-05-30Remove IPos typedef which also helps to reduce casting warnings.Nathan Moinvaziri
2020-05-24Simplify generic hash function using knuth's multiplicative hash.Nathan Moinvaziri
2020-05-24Converted compare258 to static and convert longest_match to template.Nathan Moinvaziri
2020-05-06Change two NOT_TWEAK_COMPILER to check for MIN-MATCH!=3 instead.Hans Kristian Rosbach
2020-05-06Remove several NOT_TWEAK_COMPILER checks and their legacy code.Hans Kristian Rosbach
2020-05-01Standardize fill_window implementations and abstract out slide_hash_neon for ↵Nathan Moinvaziri
ARM.
2020-04-30Replaced insert_string with quick_insert_string if length is 1.Nathan Moinvaziri
2020-04-16Fixed signed/unsigned mismatch in deflate_medium in MSVC.Nathan Moinvaziri
2020-03-18Add comment regarding long match distance bit costs.Hans Kristian Rosbach
2020-03-18Reduce size of 'match' struct to 8 bytes, this allows us to fit twoHans Kristian Rosbach
structs into a single cacheline, resulting in a measurable speedup in deflate_medium.
2020-03-18Clean up usage of bflush make more similar for each deflate strategy.Hans Kristian Rosbach
2020-03-13Clean up zng_tr_tally code.Nathan Moinvaziri
2020-02-07Removed MAX_DIST2 which is incompatible with zlib when compiled with ↵Nathan Moinvaziri
INFLATE_STRICT. It also fixes the check for proper bounds in zng_tr_tally.
2020-02-07Fixed formatting, 4 spaces for code intent, 2 spaces for preprocessor ↵Nathan Moinvaziri
indent, initial function brace on the same line as definition, removed extraneous spaces and new lines.
2019-10-22Clean up LIKELY/UNLIKELY definitions, making them upper-case to improve ↵Hans Kristian Rosbach
visibility. Add LIKELY_NULL hint. Add PREFETCH_L1, PREFETCH_L2 and PREFETCH_RW for GCC, Clang, ICC and MSVC.
2019-07-18Add zng_ prefix to internal functions to avoid linking conflicts with zlib. ↵Nathan Moinvaziri
(#363)
2019-07-18deflate_medium: fix handling of overlapping matchesIlya Leoshkevich
Fixes #361
2019-01-21Let deflate_medium be enabled by default.Hans Kristian Rosbach
2019-01-16move match.c to match_p.h and remove match.hSebastian Pop
2018-11-14Fix a bug that can crash deflate on some input when using Z_FIXED.Mark Adler
This bug was reported by Danilo Ramos of Eideticom, Inc. It has lain in wait 13 years before being found! The bug was introduced in zlib 1.2.2.2, with the addition of the Z_FIXED option. That option forces the use of fixed Huffman codes. For rare inputs with a large number of distant matches, the pending buffer into which the compressed data is written can overwrite the distance symbol table which it overlays. That results in corrupted output due to invalid distances, and can result in out-of-bound accesses, crashing the application. The fix here combines the distance buffer and literal/length buffers into a single symbol buffer. Now three bytes of pending buffer space are opened up for each literal or length/distance pair consumed, instead of the previous two bytes. This assures that the pending buffer cannot overwrite the symbol table, since the maximum fixed code compressed length/distance is 31 bits, and since there are four bytes of pending space for every three bytes of symbol space.
2018-09-17fix bug #192, oss-fuzz/9827 : MemorySanitizer:DEADLYSIGNALSebastian Pop
==4908==ERROR: MemorySanitizer: SEGV on unknown address 0x730fffffffff (pc 0x0000004b1b97 bp 0x7ffd4bf59a00 sp 0x7ffd4bf598a0 T4908) ==4908==The signal is caused by a READ memory access. #0 0x5a0599 in fizzle_matches zlib-ng/deflate_medium.c:168:12 #1 0x59ea27 in deflate_medium zlib-ng/deflate_medium.c:296:21 #2 0x5901c5 in zng_deflate zlib-ng/deflate.c:951:18 #3 0x586955 in zng_compress2 zlib-ng/compress.c:59:15 #4 0x5861eb in LLVMFuzzerTestOneInput zlib-ng/test/fuzz/compress_fuzzer.c:18:3 #5 0x4e9b48 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /src/libfuzzer/FuzzerLoop.cpp:575:15 #6 0x4a2f66 in fuzzer::RunOneTest(fuzzer::Fuzzer*, char const*, unsigned long) /src/libfuzzer/FuzzerDriver.cpp:280:6 #7 0x4b3adb in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /src/libfuzzer/FuzzerDriver.cpp:715:9 #8 0x4a2091 in main /src/libfuzzer/FuzzerMain.cpp:20:10 #9 0x7fa3d7ff582f in __libc_start_main /build/glibc-Cl5G7W/glibc-2.23/csu/libc-start.c:291 #10 0x41ec68 in _start
2018-03-22Move private defines from zconf.h and zconf-ng.h to zbuild.hMika Lindqvist
* move definition of z_size_t to zbuild.h
2017-08-17Make sure we don't export internal functionsHans Kristian Rosbach
2017-04-24Add a struct func_table and function functableInit.Hans Kristian Rosbach
The struct contains pointers to select functions to be used by the rest of zlib, and the init function selects what functions will be used depending on what optimizations has been compiled in and what instruction-sets are available at runtime. Tests done on a haswell cpu running minigzip -6 compression of a 40M file shows a 2.5% decrease in branches, and a 25-30% reduction in iTLB-loads. The reduction i iTLB-loads is likely mostly due to the inability to inline functions. This also causes a slight performance regression of around 1%, this might still be worth it to make it much easier to implement new optimized functions for various architectures and instruction sets. The performance penalty will get smaller for functions that get more alternative implementations to choose from, since there is no need to add more branches to every call of the function. Today insert_string has 1 branch to choose insert_string_sse or insert_string_c, but if we also add for example insert_string_sse4 then that would have needed another branch, and it would probably at some point hinder effective inlining too.
2017-03-24deflate_medium: Make sure we have enough lookahead before trying to scan for ↵Mika Lindqvist
matches. * longest_match: Abort if match is in future
2017-03-24deflate_medium: Remove broken overlap test.Mika Lindqvist
2017-03-24Fix typos.Mika Lindqvist
2017-02-16Avoid hashing same memory location twice by truncating overlapping byte ranges,Mika Lindqvist
it's speed optimization as the inner code also checks that previous hash value is not same as new hash value. Essentially those two checks together makes the compression a little more efficient as it can remember matches further apart. As far as I remember from my tests, the secondary path was triggered only twice in very long uncompressed file, but the gain in compression rate was still noticeable.
2017-01-30Fix missing insert_string change from merge conflictHans Kristian Rosbach
2017-01-30Merge insert_string and bulk_insert_str.Mika Lindqvist
** Partial merge of this commit, based on a8c94e9f5a3b9d3c62182bcf84e72304a3c1a6e5 Excludes changes to fill_window_sse.c, changes to fill_window_c() in deflate.c and several unrelated changes in the commit.
2017-01-30Use bulk_insert_str when adding more than one byte.Mika Lindqvist
** Partial merge of this commit, based on f8ad48ab17571c730b743c925f0e13ff83cf487f Excluding changes to fill_window_sse.c, deflate.c and deflate_p.h
2015-12-14Type cleanup.Mika Lindqvist
2015-11-03Fix for intels zlib fork, fixes their issues #2 and #3Jim Kukunas
2015-06-26Whitespace cleanupHans Kristian Rosbach
2015-06-26Make bulk_insert implementation of insert_match behave more likeHans Kristian Rosbach
the original code, this also lets us optimize the match_length=1 case.
2015-06-25No need to update hash_head.Hans Kristian Rosbach
Plus a single style change to match the other deflate algorithms.
2015-06-24Use bulk_insert_str() in deflate_medium.c too.Mika Lindqvist
2015-06-24Split deflate.cMika Lindqvist
* Separate common inlines and macros to deflate_p.h * Separate deflate_fast related code to deflate_fast.c * Separate deflate_medium related code to deflate_medium.c * Separate deflate_slow related code to deflate_slow.c
2015-05-25Style cleanup for deflate codeHans Kristian Rosbach
2015-05-23Remove unused hash_head input parameter from function emit_matchHans Kristian Rosbach