From 637e7cbdbab6a5229b51954f506e51c677739ce8 Mon Sep 17 00:00:00 2001 From: Douglas Bagnall Date: Sun, 15 May 2022 12:28:32 +1200 Subject: lzxpress: compress shortcut if we've reached maximum length A simple degenerate case for our compressor has been a large number of repeated bytes that will match the maximum length (~64k) at all 8192 search positions, 8191 of which searches are in vain because the matches are not of greater length than the first one. Here we recognise the inevitable and reduce runtime proportionately. Credit to OSS-Fuzz. REF: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=47428 Signed-off-by: Douglas Bagnall Reviewed-by: Andrew Bartlett Autobuild-User(master): Douglas Bagnall Autobuild-Date(master): Tue May 17 23:11:21 UTC 2022 on sn-devel-184 --- lib/compression/lzxpress.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/compression/lzxpress.c') diff --git a/lib/compression/lzxpress.c b/lib/compression/lzxpress.c index 71b39c1efb3..6b2aeef02f6 100644 --- a/lib/compression/lzxpress.c +++ b/lib/compression/lzxpress.c @@ -118,6 +118,10 @@ ssize_t lzxpress_compress(const uint8_t *uncompressed, found = true; best_len = len; best_offset = offset; + if (best_len == max_len) { + /* We're not going to do better than this */ + break; + } } } -- cgit v1.2.1