diff options
author | Martin Fick <mfick@nvidia.com> | 2024-11-22 17:57:17 -0800 |
---|---|---|
committer | Martin Fick <mfick@nvidia.com> | 2024-12-04 11:10:09 -0800 |
commit | fb6adb0366bc3e15f30952fe49456b1f96bcf1af (patch) | |
tree | d170546922480680845899f93913c9519f235e3e /org.eclipse.jgit/src/org/eclipse | |
parent | 44d61a3d727eb68db9e57acec0704bfc6758f878 (diff) | |
download | jgit-fb6adb0366bc3e15f30952fe49456b1f96bcf1af.tar.gz jgit-fb6adb0366bc3e15f30952fe49456b1f96bcf1af.zip |
Pack: ensure packfile is still valid while still recoverable
When copyAsIs2() needs to send a large object requiring multiple read
iterations — any of which could fail if the object isn't already in the
WindowCache — verify first that the packfile is still valid at the
latest possible moment, just before sending the header that would make
recovery impossible.
Change-Id: I234fd4b315b579a0506c8fbdea0c6787bdc09fcd
Signed-off-by: Martin Fick <mfick@nvidia.com>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java index 9073c1675a..61577a956c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java @@ -597,13 +597,19 @@ public class Pack implements Iterable<PackIndex.MutableEntry> { assert(crc2 != null); crc2.update(buf, 0, n); } + cnt -= n; if (!isHeaderWritten) { + if (invalid && cnt > 0) { + // Since this is not the last iteration and the packfile is invalid, + // better to assume the iterations will not all complete here while + // it is still likely recoverable. + throw new StoredObjectRepresentationNotAvailableException(invalidatingCause); + } out.writeHeader(src, inflatedLength); isHeaderWritten = true; } out.write(buf, 0, n); pos += n; - cnt -= n; } if (validate) { assert(crc2 != null); |