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
This commit is contained in:
Tim Kientzle 2004-06-04 01:36:10 +00:00
parent 020a53a0cc
commit 1a74b99db7

View File

@ -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)