From a14455dfd7ac61e13f2ea8c7d789463efd8eeb72 Mon Sep 17 00:00:00 2001 From: wh Date: Thu, 17 Dec 2020 18:14:32 +0000 Subject: [PATCH] dfs: handle short copies `copy` is documented as possibly returning a smaller number of bytes than requested. In practice, this can occur if a block is cached and the reader never pulls in the file to check its size. Bug: 565874 Change-Id: I1e53b3d2f4ab09334178934dc0ef74ea99045cd3 Signed-off-by: wh Signed-off-by: Matthias Sohn --- .../jgit/internal/storage/dfs/DfsPackFile.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 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 b1e95520c..96ca690c1 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 @@ -607,8 +607,15 @@ private IOException packfileIsTruncated() { private void readFully(long position, byte[] dstbuf, int dstoff, int cnt, DfsReader ctx) throws IOException { - if (ctx.copy(this, position, dstbuf, dstoff, cnt) != cnt) - throw new EOFException(); + while (cnt > 0) { + int copied = ctx.copy(this, position, dstbuf, dstoff, cnt); + if (copied == 0) { + throw new EOFException(); + } + position += copied; + dstoff += copied; + cnt -= copied; + } } ObjectLoader load(DfsReader ctx, long pos)