From 1a74b99db7222cf76660e60bcbcc6cf4ee6aca25 Mon Sep 17 00:00:00 2001 From: Tim Kientzle Date: Fri, 4 Jun 2004 01:36:10 +0000 Subject: [PATCH] Be more careful about the initial read (used for "tasting" the compression): * Check for and return input errors * Treat empty file (zero-length read) as a fatal error --- lib/libarchive/archive_read.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/libarchive/archive_read.c b/lib/libarchive/archive_read.c index 0ecd24b0b18..57923ce4acb 100644 --- a/lib/libarchive/archive_read.c +++ b/lib/libarchive/archive_read.c @@ -103,7 +103,7 @@ archive_read_open(struct archive *a, void *client_data, archive_close_callback *closer) { const void *buffer; - size_t bytes_read; + ssize_t bytes_read; int high_bidder; int e; @@ -130,6 +130,17 @@ archive_read_open(struct archive *a, void *client_data, /* Read first block now for format detection. */ bytes_read = (a->client_reader)(a, a->client_data, &buffer); + /* client_reader should have already set error information. */ + if (bytes_read < 0) + return (ARCHIVE_FATAL); + + /* An empty archive is a serious error. */ + if (bytes_read == 0) { + archive_set_error(a, ARCHIVE_ERRNO_FILE_FORMAT, + "Empty input file"); + return (ARCHIVE_FATAL); + } + /* Select a decompression routine. */ high_bidder = choose_decompressor(a, buffer, bytes_read); if (high_bidder < 0)