Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Aniszczyk2010-05-03 07:40:36 +0000
committerCode Review2010-05-03 07:40:36 +0000
commitd011a377cbf30738a1a2d9b156cf869346adb537 (patch)
treecacc642437f46dbb15050fdf6332f09a24ad56e6
parent28e42cb463413e446b32360eec3c513557a3c6e9 (diff)
parentc10e13415705d63e4d5d2487ca6fff1fe1ff10bb (diff)
downloadjgit-d011a377cbf30738a1a2d9b156cf869346adb537.tar.gz
jgit-d011a377cbf30738a1a2d9b156cf869346adb537.tar.xz
jgit-d011a377cbf30738a1a2d9b156cf869346adb537.zip
Merge "Fix handling of corruption for truncated objects"
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/UnpackedObjectLoader.java19
1 files changed, 15 insertions, 4 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/UnpackedObjectLoader.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/UnpackedObjectLoader.java
index 005df4b98d..96a1f80241 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/UnpackedObjectLoader.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/UnpackedObjectLoader.java
@@ -114,8 +114,13 @@ public class UnpackedObjectLoader extends ObjectLoader {
int avail = 0;
while (!inflater.finished() && avail < hdr.length)
try {
- avail += inflater.inflate(hdr, avail, hdr.length
- - avail);
+ int uncompressed = inflater.inflate(hdr, avail,
+ hdr.length - avail);
+ if (uncompressed == 0) {
+ throw new CorruptObjectException(id,
+ "bad stream, corrupt header");
+ }
+ avail += uncompressed;
} catch (DataFormatException dfe) {
final CorruptObjectException coe;
coe = new CorruptObjectException(id, "bad stream");
@@ -172,8 +177,14 @@ public class UnpackedObjectLoader extends ObjectLoader {
private void decompress(final AnyObjectId id, final Inflater inf, int p)
throws CorruptObjectException {
try {
- while (!inf.finished())
- p += inf.inflate(bytes, p, objectSize - p);
+ while (!inf.finished()) {
+ int uncompressed = inf.inflate(bytes, p, objectSize - p);
+ p += uncompressed;
+ if (uncompressed == 0 && !inf.finished()) {
+ throw new CorruptObjectException(id,
+ "bad stream, corrupt header");
+ }
+ }
} catch (DataFormatException dfe) {
final CorruptObjectException coe;
coe = new CorruptObjectException(id, "bad stream");

Back to the top