diff options
author | Jeff King <peff@peff.net> | 2018-06-14 23:31:13 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-06-18 09:13:57 -0700 |
commit | 9d2e330b1795222c2c816afa46138e7ff4ebec8e (patch) | |
tree | 615745f2611f52e42bf28137ab9594fd773a3523 /t/t5310-pack-bitmaps.sh | |
parent | Git 2.16.4 (diff) | |
download | tgif-9d2e330b1795222c2c816afa46138e7ff4ebec8e.tar.xz |
ewah_read_mmap: bounds-check mmap reads
The on-disk ewah format tells us how big the ewah data is,
and we blindly read that much from the buffer without
considering whether the mmap'd data is long enough, which
can lead to out-of-bound reads.
Let's make sure we have data available before reading it,
both for the ewah header/footer as well as for the bit data
itself. In particular:
- keep our ptr/len pair in sync as we move through the
buffer, and check it before each read
- check the size for integer overflow (this should be
impossible on 64-bit, as the size is given as a 32-bit
count of 8-byte words, but is possible on a 32-bit
system)
- return the number of bytes read as an ssize_t instead of
an int, again to prevent integer overflow
- compute the return value using a pointer difference;
this should yield the same result as the existing code,
but makes it more obvious that we got our computations
right
The included test is far from comprehensive, as it just
picks a static point at which to truncate the generated
bitmap. But in practice this will hit in the middle of an
ewah and make sure we're at least exercising this code.
Reported-by: Luat Nguyen <root@l4w.io>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t5310-pack-bitmaps.sh')
-rwxr-xr-x | t/t5310-pack-bitmaps.sh | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/t/t5310-pack-bitmaps.sh b/t/t5310-pack-bitmaps.sh index 20e2473a03..b11bc392a8 100755 --- a/t/t5310-pack-bitmaps.sh +++ b/t/t5310-pack-bitmaps.sh @@ -331,4 +331,17 @@ test_expect_success 'pack reuse respects --incremental' ' git show-index <empty.idx >actual && test_cmp expect actual ' + +test_expect_success 'truncated bitmap fails gracefully' ' + git repack -ad && + git rev-list --use-bitmap-index --count --all >expect && + bitmap=$(ls .git/objects/pack/*.bitmap) && + test_when_finished "rm -f $bitmap" && + head -c 512 <$bitmap >$bitmap.tmp && + mv -f $bitmap.tmp $bitmap && + git rev-list --use-bitmap-index --count --all >actual 2>stderr && + test_cmp expect actual && + test_i18ngrep corrupt stderr +' + test_done |