From bc533e5afff62f35c69103c0bb84b3640bf17f34 Mon Sep 17 00:00:00 2001 From: Xi Wang Date: Sun, 20 Jan 2013 18:17:20 -0500 Subject: [PATCH] Fix overflow checking in archive_entry_sparse_add_entry() 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libarchive/archive_entry_sparse.c b/libarchive/archive_entry_sparse.c index 10c54474a..fed74f512 100644 --- a/libarchive/archive_entry_sparse.c +++ b/libarchive/archive_entry_sparse.c @@ -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; -- 2.47.2