summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2010-04-16 15:55:18 -0700
committerShawn O. Pearce <spearce@spearce.org>2010-04-16 15:56:23 -0700
commit06ee913c8d5cd1afaa3c5573430f07e5655e1edf (patch)
treebb18a62ad217842daf3a2529c8af8144ad2db38e /org.eclipse.jgit
parentd29618dd41d1dd52972524b4e25679bcf7baa39c (diff)
downloadjgit-06ee913c8d5cd1afaa3c5573430f07e5655e1edf.tar.gz
jgit-06ee913c8d5cd1afaa3c5573430f07e5655e1edf.zip
IndexPack: Correct thin pack fix using less than 20 bytes
If we need to append less than 20 bytes in order to fix a thin pack and make it complete, we need to set the length of our file back to the actual number of bytes used because the original SHA-1 footer was not completely overwritten. That extra data will confuse the header and footer fixup logic when it tries to read to the end of the file. This isn't a very common case to occur, which is why we've never seen it before. Getting a delta that requires a whole object which uses less than 20 bytes in pack representation is really hard. Generally a delta generator won't make these, because the delta would be bigger than simply deflating the whole object. I only managed to do this with a hand-crafted pack file where a 1 byte delta was pointed to a 1 byte whole object. Normally we try really hard to avoid truncating, because its typically not safe across network filesystems. But the odds of this occurring are very low. This truncation is done on a file we have open for writing, will append more content onto, and is a temporary file that we won't move into position for others to see until we've validated its SHA-1 is sane. I don't think the truncate on NFS issue is something we need to worry about here. Change-Id: I102b9637dfd048dc833c050890d142f43c1e75ae Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/IndexPack.java8
1 files changed, 8 insertions, 0 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/IndexPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/IndexPack.java
index 23faa42a24..29f200c52d 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/IndexPack.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/IndexPack.java
@@ -601,6 +601,14 @@ public class IndexPack {
throw new MissingObjectException(base, "delta base");
}
+ if (end - originalEOF < 20) {
+ // Ugly corner case; if what we appended on to complete deltas
+ // doesn't completely cover the SHA-1 we have to truncate off
+ // we need to shorten the file, otherwise we will include part
+ // of the old footer as object content.
+ packOut.setLength(end);
+ }
+
fixHeaderFooter(packcsum, packDigest.digest());
}