From: Terry Parker Date: Thu, 7 Apr 2016 23:24:10 +0000 (-0700) Subject: Filter corrupt objects from DfsReader.selectObjectRepresentation() X-Git-Tag: v4.4.0.201605041135-m1~20 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2708b11b6c6f0e6a1ecd4a6e430756501a783bc6;p=jgit.git Filter corrupt objects from DfsReader.selectObjectRepresentation() PackWriter.writeObject() can get into an infinite loop when corrupt packs are present. When it finds a pack file with an object that can be reused it calls DfsPackFile.copyAsIs(). If that method sees an invalid CRC, it adds the object to the DfsPackFile's corrupt object list and throws a CorruptObjectException, which it later catches as an IOException and wraps in a StoredObjectRepresentationNotAvailableException. PackWriter.writeObjectImpl() catches that SORNAE and retries the operation by calling DfsReader.selectObjectRepresentation(). But currently that method returns the same object which was just seen to be corrupt. Change DfsPackFile.isCorrupt() from private to package private, and use that method in DfsReader.selectObjectRepresentation() to filter out corrupt objects. The stack traces that show the problem are: org.eclipse.jgit.errors.CorruptObjectException.(CorruptObjectException.java:113) org.eclipse.jgit.internal.storage.dfs.DfsPackFile.copyAsIs(DfsPackFile.java:624) org.eclipse.jgit.internal.storage.dfs.DfsReader.copyObjectAsIs(DfsReader.java:491) org.eclipse.jgit.internal.storage.pack.PackWriter.writeObjectImpl(PackWriter.java:1478) org.eclipse.jgit.internal.storage.pack.PackWriter.writeObject(PackWriter.java:1455) org.eclipse.jgit.internal.storage.dfs.DfsPackFile.getPackIndex(DfsPackFile.java:228) org.eclipse.jgit.internal.storage.dfs.DfsReader.findAllFromPack(DfsReader.java:476) org.eclipse.jgit.internal.storage.dfs.DfsReader.selectObjectRepresentation(DfsReader.java:455) org.eclipse.jgit.internal.storage.pack.PackWriter.writeObjectImpl(PackWriter.java:1492) org.eclipse.jgit.internal.storage.pack.PackWriter.writeObject(PackWriter.java:1455) Change-Id: Iad7bbcaed1f11a6aa3b4f5af911a73a34c0fabfd Signed-off-by: Terry Parker --- diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java index 96f1d542ca..4eabb03163 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java @@ -1189,7 +1189,7 @@ public final class DfsPackFile { } } - private boolean isCorrupt(long offset) { + boolean isCorrupt(long offset) { LongList list = corruptObjects; if (list == null) return false; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java index 1665c2c772..66421e2a88 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java @@ -476,7 +476,7 @@ public final class DfsReader extends ObjectReader implements ObjectReuseAsIs { PackIndex idx = pack.getPackIndex(this); for (ObjectToPack otp : objects) { long p = idx.findOffset(otp); - if (0 < p) { + if (0 < p && !pack.isCorrupt(p)) { otp.setOffset(p); tmp.add((DfsObjectToPack) otp); }