From d32ea29f60838878312e9f7d61f0bfef361a2350 Mon Sep 17 00:00:00 2001 From: Enno Boland Date: Sun, 20 Aug 2023 23:16:49 +0200 Subject: [PATCH] tools/fs-common.c: workaround error at end of file OpenBSD requests a chunk of data at the end of the file. Currently sqsh_file_reader_advance() returns an error in this case. This commit works around this behavior by returning early when zero size is requested. --- tools/fs-common.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/fs-common.c b/tools/fs-common.c index 5e27fb454..01d3f570f 100644 --- a/tools/fs-common.c +++ b/tools/fs-common.c @@ -145,6 +145,15 @@ fs_common_read( size = file_size - offset; } + + // This works around a bug in sqsh_file_reader_advance: + // Reading a 0 size at the end of the file will return + // SQSH_ERROR_OUT_OF_BOUNDS. This should succeed instead, + // providing an empty buffer. + if (size == 0) { + return 0; + } + rv = sqsh_file_reader_advance(*reader, offset, size); if (rv < 0) { goto out;