]> source.dussan.org Git - jgit.git/commitdiff
Make sure ref to prune is in packed refs 31/1173231/9
authorFabio Ponciroli <ponch78@gmail.com>
Wed, 6 Dec 2023 13:38:21 +0000 (14:38 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Sat, 9 Dec 2023 14:28:17 +0000 (14:28 +0000)
RefDirectory:pack might raise an NPE when deleting loose
refs as final part of the RefDirectory.pack().

This is what the code does:
1) packed ref update: update the list of refs which will be
persisted in packed-refs
2) persit packed-refs: flush on file the refs computed in #1
3) prune loose refs: prune loose refs that have been packed in #2

The code correctly locks the packed-refs file during phases 1 to 3.
However, it makes the wrong assumption of considering
the loose refs set as immutable between phases 1 and 3.

The number and values of loose refs on the filesystem can mutate
at any time whilst the RefDirectory.pack() is in progress.
Assuming the contrary can lead to an NPE when retrieving refs
from the mutable loose refs list during phase #3.

Make sure that the ref is not null before dereferencing its
object-id value.

Bug: jgit-4
Change-Id: I2cd01f8a880f3c6561ad978a389ec2db45b6018b

org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java

index f0676d9beca523e02fd63d54840f5be12d636c52..9f31e688c3a21d213031b95fae715010b0997605 100644 (file)
@@ -813,7 +813,7 @@ public class RefDirectory extends RefDatabase {
                                                }
                                                Ref packedRef = newPacked.get(refName);
                                                ObjectId clr_oid = currentLooseRef.getObjectId();
-                                               if (clr_oid != null
+                                               if (clr_oid != null && packedRef != null
                                                                && clr_oid.equals(packedRef.getObjectId())) {
                                                        RefList<LooseRef> curLoose, newLoose;
                                                        do {