]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Fix an error test on the result from fread 29/head
authorTristan Ravitch <travitch@cs.wisc.edu>
Fri, 2 Nov 2012 14:49:44 +0000 (09:49 -0500)
committerTristan Ravitch <travitch@cs.wisc.edu>
Fri, 2 Nov 2012 15:03:58 +0000 (10:03 -0500)
fread returns a short byte count on error (and ferror has to be used
to determine if it really was an error).  There was a check for < 0,
which fread cannot return.

libarchive/archive_read_open_file.c

index b1aac0a7cbf0b034cbf7a5090da2aaf7cc7e88ed..3a33c258ee701d96ea0abb9270e291ac4ffdcab0 100644 (file)
@@ -108,11 +108,11 @@ static ssize_t
 file_read(struct archive *a, void *client_data, const void **buff)
 {
        struct read_FILE_data *mine = (struct read_FILE_data *)client_data;
-       ssize_t bytes_read;
+       size_t bytes_read;
 
        *buff = mine->buffer;
        bytes_read = fread(mine->buffer, 1, mine->block_size, mine->f);
-       if (bytes_read < 0) {
+       if (bytes_read < mine->block_size && ferror(mine->f)) {
                archive_set_error(a, errno, "Error reading file");
        }
        return (bytes_read);