]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Fix overflow checking in archive_entry_sparse_add_entry() 33/head
authorXi Wang <xi.wang@gmail.com>
Sun, 20 Jan 2013 23:17:20 +0000 (18:17 -0500)
committerXi Wang <xi@mit.edu>
Sat, 16 Mar 2013 03:17:20 +0000 (23:17 -0400)
gcc will optimize the overflow check x + y < 0 (assuming x, y >= 0)
into false, since signed integer overflow is undefined behavior in C.
Use a safe precondition check instead.

libarchive/archive_entry_sparse.c

index 10c54474a379640f4533bc44aa62de67e9537924..fed74f5121d72570248080da3c4b2bd4e9dd9842 100644 (file)
@@ -58,7 +58,7 @@ archive_entry_sparse_add_entry(struct archive_entry *entry,
        if (offset < 0 || length < 0)
                /* Invalid value */
                return;
-       if (offset + length < 0 ||
+       if (offset > INT64_MAX - length ||
            offset + length > archive_entry_size(entry))
                /* A value of "length" parameter is too large. */
                return;