summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorMinh Thai <mthai@google.com>2019-02-13 12:16:42 -0800
committerMinh Thai <mthai@google.com>2019-02-13 12:48:05 -0800
commit2b7fa04dad12c57389281076d54085e536916f19 (patch)
tree8bba6ce8ceb235cae07eb02774020e8ceec38bca /org.eclipse.jgit
parent59e75961603f649e6e9d4118f8540e629981e90d (diff)
downloadjgit-2b7fa04dad12c57389281076d54085e536916f19.tar.gz
jgit-2b7fa04dad12c57389281076d54085e536916f19.zip
Fix bug in copyPackBypassCache's skip 'PACK' header logic
Bug caused the pack to be 12 bytes short when cold cache. Also added test for copyPackAsIs method. Change-Id: Idf8fb0e50d1215245d4b032e2e00df4b218c115f Signed-off-by: Minh Thai <mthai@google.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java25
1 files changed, 13 insertions, 12 deletions
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 7d891b5230..5b574e49a9 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
@@ -464,6 +464,9 @@ public final class DfsPackFile extends BlockBasedFile {
while (0 < remaining) {
DfsBlock b = cache.getOrLoad(this, position, ctx, () -> rc);
int ptr = (int) (position - b.start);
+ if (b.size() <= ptr) {
+ throw packfileIsTruncated();
+ }
int n = (int) Math.min(b.size() - ptr, remaining);
b.write(out, position, n);
position += n;
@@ -481,6 +484,9 @@ public final class DfsPackFile extends BlockBasedFile {
DfsBlock b = cache.get(key, alignToBlock(position));
if (b != null) {
int ptr = (int) (position - b.start);
+ if (b.size() <= ptr) {
+ throw packfileIsTruncated();
+ }
int n = (int) Math.min(b.size() - ptr, remaining);
b.write(out, position, n);
position += n;
@@ -490,23 +496,18 @@ public final class DfsPackFile extends BlockBasedFile {
continue;
}
+ // Need to skip the 'PACK' header for the first read
+ int ptr = packHeadSkipped ? 0 : 12;
buf.position(0);
- int n = read(rc, buf);
- if (n <= 0) {
+ int bufLen = read(rc, buf);
+ if (bufLen <= ptr) {
throw packfileIsTruncated();
- } else if (n > remaining) {
- n = (int) remaining;
- }
-
- if (!packHeadSkipped) {
- // Need skip the 'PACK' header for the first read
- out.write(buf.array(), 12, n - 12);
- packHeadSkipped = true;
- } else {
- out.write(buf.array(), 0, n);
}
+ int n = (int) Math.min(bufLen - ptr, remaining);
+ out.write(buf.array(), ptr, n);
position += n;
remaining -= n;
+ packHeadSkipped = true;
}
return position;
}