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
-/* $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
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);