summaryrefslogtreecommitdiff
path: root/cache.h
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2016-02-25 14:22:52 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-02-25 19:32:43 (GMT)
commit47fe3f6ef0f5a336db90d816c5fb4330ffa23668 (patch)
tree86425f817d2e2116956355c387cafd78b50e9877 /cache.h
parenta1283866bab1cd12da57b3e427664180f5dee333 (diff)
downloadgit-47fe3f6ef0f5a336db90d816c5fb4330ffa23668.zip
git-47fe3f6ef0f5a336db90d816c5fb4330ffa23668.tar.gz
git-47fe3f6ef0f5a336db90d816c5fb4330ffa23668.tar.bz2
nth_packed_object_offset: bounds-check extended offset
If a pack .idx file has a corrupted offset for an object, we may try to access an offset in the .idx or .pack file that is larger than the file's size. For the .pack case, we have use_pack() to protect us, which realizes the access is out of bounds. But if the corrupted value asks us to look in the .idx file's secondary 64-bit offset table, we blindly add it to the mmap'd index data and access arbitrary memory. We can fix this with a simple bounds-check compared to the size we found when we opened the .idx file. Note that there's similar code in index-pack that is triggered only during "index-pack --verify". To support both, we pull the bounds-check into a separate function, which dies when it sees a corrupted file. It would be nice if we could return an error, so that the pack code could try to find a good copy of the object elsewhere. Currently nth_packed_object_offset doesn't have any way to return an error, but it could probably use "0" as a sentinel value (since no object can start there). This is the minimal fix, and we can improve the resilience later on top. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'cache.h')
-rw-r--r--cache.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/cache.h b/cache.h
index 4427945..6c9aaa1 100644
--- a/cache.h
+++ b/cache.h
@@ -1237,6 +1237,16 @@ extern void clear_delta_base_cache(void);
extern struct packed_git *add_packed_git(const char *, int, int);
/*
+ * Make sure that a pointer access into an mmap'd index file is within bounds,
+ * and can provide at least 8 bytes of data.
+ *
+ * Note that this is only necessary for variable-length segments of the file
+ * (like the 64-bit extended offset table), as we compare the size to the
+ * fixed-length parts when we open the file.
+ */
+extern void check_pack_index_ptr(const struct packed_git *p, const void *ptr);
+
+/*
* Return the SHA-1 of the nth object within the specified packfile.
* Open the index if it is not already open. The return value points
* at the SHA-1 within the mmapped index. Return NULL if there is an