diff --git a/sha1_file.c b/sha1_file.c
index 275332618b34738154bc53848247fe2b19057974..a4c65c5e6b07e34dae941ddbe22fd6512c28bd56 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1076,6 +1076,8 @@ unsigned char *use_pack(struct packed_git *p,
 		die("packfile %s cannot be accessed", p->pack_name);
 	if (offset > (p->pack_size - 20))
 		die("offset beyond end of packfile (truncated pack?)");
+	if (offset < 0)
+		die("offset before end of packfile (broken .idx?)");
 
 	if (!win || !in_window(win, offset)) {
 		if (win)
diff --git a/t/t5313-pack-bounds-checks.sh b/t/t5313-pack-bounds-checks.sh
index 0717746479a4ca82302d67faf91bf71c76bc7ceb..a8a587abc3799f069deab3bc48914cea81bb15cf 100755
--- a/t/t5313-pack-bounds-checks.sh
+++ b/t/t5313-pack-bounds-checks.sh
@@ -136,7 +136,7 @@ test_expect_success 'bogus offset into v2 extended table' '
 	test_must_fail git index-pack --verify $pack
 '
 
-test_expect_failure 'bogus offset inside v2 extended table' '
+test_expect_success 'bogus offset inside v2 extended table' '
 	# We need two objects here, so we can plausibly require
 	# an extended table (if the first object were larger than 2^31).
 	do_pack "$object $(git rev-parse HEAD)" --index-version=2 &&