eclipse-jgit / jgit

JGit, the Java implementation of git
https://www.eclipse.org/jgit/
Other
117 stars 33 forks source link

NPE when calling RefDirectory:pack #4

Closed barbasa closed 6 months ago

barbasa commented 9 months ago

RefDirectory:pack might raise an NPE when deleting loose refs as final part of the RefDirectory.pack():

java.lang.NullPointerException
       at org.eclipse.jgit.internal.storage.file.RefDirectory.pack(RefDirectory.java:817)
       at org.eclipse.jgit.internal.storage.file.RefDirectory.pack(RefDirectory.java:729)
       at org.eclipse.jgit.internal.storage.file.PackedBatchRefUpdate.execute(PackedBatchRefUpdate.java:153)
       at org.eclipse.jgit.lib.BatchRefUpdate.execute(BatchRefUpdate.java:589)
       at org.eclipse.jgit.transport.FetchProcess.executeImp(FetchProcess.java:249)
       at org.eclipse.jgit.transport.FetchProcess.execute(FetchProcess.java:105)
       at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1462)
       at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1390)

This is happening because the code correctly locks the packed-refs file in RefDirectory:pack. However, it makes the wrong assumption considering the loose refs set as immutable between during the whole packing process.

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.

msohn commented 6 months ago

This was fixed by https://eclipse.gerrithub.io/c/eclipse-jgit/jgit/+/1173231