diff options
author | Robin Rosenberg <robin.rosenberg@dewire.com> | 2010-05-01 09:23:03 +0200 |
---|---|---|
committer | Robin Rosenberg <robin.rosenberg@dewire.com> | 2010-05-01 09:50:38 +0200 |
commit | c10e13415705d63e4d5d2487ca6fff1fe1ff10bb (patch) | |
tree | bcac814a575b402b4d3acc7db7c4a7ffa248e31a | |
parent | 23583e59bbd707d4f10e15af7c1c4f2874e13685 (diff) | |
download | jgit-c10e13415705d63e4d5d2487ca6fff1fe1ff10bb.tar.gz jgit-c10e13415705d63e4d5d2487ca6fff1fe1ff10bb.zip |
Fix handling of corruption for truncated objects
If a loose object was corrupted by truncation, JGit would hang.
Change-Id: I7e4c14f44183a5fcb37c1562e81682bddeba80ad
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/lib/UnpackedObjectLoader.java | 19 |
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"); |