From b1839a20e506c46253567202fff26b27592e4a5c Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Tue, 3 Jun 2025 22:00:13 +0200 Subject: [PATCH] archive_read: Handle sparse holes at end of file If a sparse hole is located at the end of an entry, then the tar parser returns ARCHIVE_EOF while updating the offset where 0 bytes of data will follow. If archive_read_data encounters such an ARCHIVE_EOF return value, it has to recheck if the offsets (data offset and output offset) still match. If they do not match, it has to keep filling 0 bytes. This changes assumes that it's okay to call archive_read_data_block again after an EOF. As far as I understood the parsers so far, this should be okay, since it's always ARCHIVE_EOF afterwards. Fixes https://github.com/libarchive/libarchive/issues/1194 Signed-off-by: Tobias Stoeckmann --- libarchive/archive_read.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libarchive/archive_read.c b/libarchive/archive_read.c index 50db87017..ea58c6ed0 100644 --- a/libarchive/archive_read.c +++ b/libarchive/archive_read.c @@ -834,7 +834,9 @@ archive_read_data(struct archive *_a, void *buff, size_t s) r = archive_read_data_block(a, &read_buf, &a->read_data_remaining, &a->read_data_offset); a->read_data_block = read_buf; - if (r == ARCHIVE_EOF) + if (r == ARCHIVE_EOF && + a->read_data_offset == a->read_data_output_offset && + a->read_data_remaining == 0) return (bytes_read); /* * Error codes are all negative, so the status -- 2.47.2