]> source.dussan.org Git - jgit.git/commitdiff
PackFile: Fix copy as-is for small objects 49/2649/1
authorShawn O. Pearce <spearce@spearce.org>
Sat, 5 Mar 2011 02:56:16 +0000 (18:56 -0800)
committerShawn O. Pearce <spearce@spearce.org>
Sat, 5 Mar 2011 02:56:16 +0000 (18:56 -0800)
When I disabled validation I broke the code that handled copying small
objects whose contents were below 8192 bytes in size but spanned over
the end of one window and into the next window.  These objects did not
ever populate the temporary write buffer, resulting in garbage writing
into the output stream instead of valid object contents.

Change-Id: Ie26a2aaa885d0eee4888a9b12c222040ee4a8562
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/PackFile.java

index d8d986fb042dea450acbc1de2a6ed2e053f8bc55..2bf8160e28d0bf4aee3aca5cd3ea63da13af9961 100644 (file)
@@ -468,6 +468,16 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> {
                        // Tiny optimization: Lots of objects are very small deltas or
                        // deflated commits that are likely to fit in the copy buffer.
                        //
+                       if (!validate) {
+                               long pos = dataOffset;
+                               long cnt = dataLength;
+                               while (cnt > 0) {
+                                       final int n = (int) Math.min(cnt, buf.length);
+                                       readFully(pos, buf, 0, n, curs);
+                                       pos += n;
+                                       cnt -= n;
+                               }
+                       }
                        out.writeHeader(src, inflatedLength);
                        out.write(buf, 0, (int) dataLength);
                } else {