]> source.dussan.org Git - jgit.git/commitdiff
Filter corrupt objects from DfsReader.selectObjectRepresentation() 95/70195/1
authorTerry Parker <tparker@google.com>
Thu, 7 Apr 2016 23:24:10 +0000 (16:24 -0700)
committerTerry Parker <tparker@google.com>
Thu, 7 Apr 2016 23:25:05 +0000 (16:25 -0700)
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.<init>(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 <tparker@google.com>
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java

index 96f1d542caa26e6940bfe6e457a63906b6f805ad..4eabb031637d54b8808e9e45dd516f4ab4c84b64 100644 (file)
@@ -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;
index 1665c2c772b781c2eaba0451133788944d789146..66421e2a88fff11730bd1ec5881b4ffdbd747da4 100644 (file)
@@ -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);
                        }