summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2022-08-29 19:42:02 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2022-08-29 19:42:02 +0000
commit28ce494af1e8a23f169587a742956953eff1eb37 (patch)
tree2565c5182ff0e50b5ae7d9a3fc303b7efe2e9560
parent2a962f912510c27520b21439f6243b306d259f6f (diff)
Fix growth check in compress(1)/gzip(1)
If a compressed file is larger than its expanded version, compress(1) and gzip(1) don't compress unless -f is given. As found by gkoehler, the check is not quite correct for very small files or files with sufficiently random data. Fix the check so that slight growth still triggers the check. ok millert
-rw-r--r--usr.bin/compress/main.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/usr.bin/compress/main.c b/usr.bin/compress/main.c
index 66cd2287c3b..81d7bd590c0 100644
--- a/usr.bin/compress/main.c
+++ b/usr.bin/compress/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.100 2022/04/10 18:05:39 jca Exp $ */
+/* $OpenBSD: main.c,v 1.101 2022/08/29 19:42:01 tb Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -582,7 +582,8 @@ docompress(const char *in, char *out, const struct compressor *method,
error = FAILURE;
}
- if (!force && !cat && info.total_out >= info.total_in) {
+ if (!force && !cat && (info.hlen >= info.total_in ||
+ info.total_out >= info.total_in - info.hlen)) {
if (verbose > 0)
fprintf(stderr, "file would grow; left unmodified\n");
(void) unlink(out);