]> source.dussan.org Git - jgit.git/commit
GraphObjectIndex: fix search in findGraphPosition 50/201850/5
authorJonathan Tan <jonathantanmy@google.com>
Mon, 8 May 2023 20:55:40 +0000 (13:55 -0700)
committerJonathan Tan <jonathantanmy@google.com>
Tue, 23 May 2023 20:57:32 +0000 (13:57 -0700)
commit6b3b2b33a528458aa23428db7d43655aa0d883d5
tree900530bace22ab191e7c12c9af1ae71fc47ec75b
parent4562e79e234696ae3e1601db9bf8b73a1ef7edf8
GraphObjectIndex: fix search in findGraphPosition

In findGraphPosition, when there is no object whose OID starts with
the first byte of the sought OID, low equals high. This violates an
invariant of the loop, and when the sought OID is lexicographically
greater than every other OID in the repository, causes an
ArrayIndexOutOfBoundsException (because we're trying to read outside the
list of OIDs).

Therefore, check the "low < high" condition at the start of the loop,
not only after the first iteration.

Change-Id: Ic8ac198c151bd161c4996b9e7cb6e6660f151733
Helped-by: Ivan Frade <ifrade@google.com>
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/commitgraph/GraphObjectIndexTest.java [new file with mode: 0644]
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/commitgraph/GraphObjectIndex.java