From 7b5cf6d1679bf0fa3381fb0fdd4f10ec48a08244 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Wed, 3 Dec 2025 15:43:07 -0500 Subject: unalf: Fix -F for small input files. --- src/io.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/io.c b/src/io.c index 294751a..cc50b8b 100644 --- a/src/io.c +++ b/src/io.c @@ -73,14 +73,26 @@ static void sanity_check_header(long pos) { if(compsize > (s.st_size - pos)) { fatal = !(opts.force || opts.listonly); - fprintf(stderr, "%s: %s: compressed size for header #%d is bigger than the rest of the file (truncated?), use -F to override.\n", fatal ? "fatal" : "warning", self, headers_read); - if(fatal) exit(1); + fprintf(stderr, "%s: %s: compressed size for header #%d is bigger than the rest of the file (truncated?)", self, fatal ? "fatal" : "warning", headers_read); + if(fatal) { + fputs(", use -F to override.\n", stderr); + exit(1); + } + fputs("\n", stderr); } - if(compsize > origsize * 2) { + /* 0 byte input gives a 2-byte output, 1 byte input gives 4, + 2 bytes gives 5. + don't complain about these. starting with any 3 byte input, + the compressed size will always be under 2x the input size. */ + if(origsize > 2 && compsize > 5 && compsize > origsize * 2) { fatal = !(opts.force || opts.listonly); - fprintf(stderr, "%s: %s: compressed size for header #%d is over twice the uncompressed size (corrupt?), use -F to override.\n", fatal ? "fatal": "warning", self, headers_read); - if(fatal) exit(1); + fprintf(stderr, "%s: %s: compressed size for header #%d is over twice the uncompressed size (corrupt?)", self, fatal ? "fatal": "warning", headers_read); + if(fatal) { + fputs(", use -F to override.\n", stderr); + exit(1); + } + fputs("\n", stderr); } } -- cgit v1.2.3