]> source.dussan.org Git - jgit.git/commitdiff
DfsBlock: throw DataFormatException on 0 bytes 42/74342/1
authorShawn Pearce <spearce@spearce.org>
Thu, 2 Jun 2016 04:48:21 +0000 (21:48 -0700)
committerShawn Pearce <spearce@spearce.org>
Thu, 2 Jun 2016 04:48:21 +0000 (21:48 -0700)
setInput should always push at least 1 byte into the Inflater.  If 0
bytes (or negative!) are being sent the DfsBlock is inconsistent with
the position passed in.  This indicates a severe programming problem
in the caller, and may cause an infinite loop in DfsReader.

Today we saw a handful of live examples of this but don't know what
the cause is.  Guard against this error condition and throw with a
more verbose failure, which may prevent an infinite loop.  Callers
will eventually catch DataFormatException and rethrow with more detail
about the object that cannot be inflated, with the DFE in the chain.

Change-Id: I64ed2a471520e48283675c6210c6db8a60634635

org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlock.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsInserter.java

index 79265363e05e0480966ff1d2bf3ff22cc09072d9..4a33fb87e1ebd3e0fa14abaa8be1058e677f2708 100644 (file)
@@ -88,9 +88,16 @@ final class DfsBlock {
                return n;
        }
 
-       int setInput(long pos, Inflater inf) {
+       int setInput(long pos, Inflater inf) throws DataFormatException {
                int ptr = (int) (pos - start);
                int cnt = block.length - ptr;
+               if (cnt <= 0) {
+                       throw new DataFormatException(cnt + " bytes to inflate:" //$NON-NLS-1$
+                                       + " at pos=" + pos //$NON-NLS-1$
+                                       + "; block.start=" + start //$NON-NLS-1$
+                                       + "; ptr=" + ptr //$NON-NLS-1$
+                                       + "; block.length=" + block.length); //$NON-NLS-1$
+               }
                inf.setInput(block, ptr, cnt);
                return cnt;
        }
index 3e8deac0f02b60071877230e1332151178664620..c57c41741f4f67ddb0184b39c47ae45a071df585 100644 (file)
@@ -484,7 +484,8 @@ public class DfsInserter extends ObjectInserter {
                        }
                }
 
-               private int setInput(long pos, Inflater inf) throws IOException {
+               private int setInput(long pos, Inflater inf)
+                               throws IOException, DataFormatException {
                        if (pos < currPos)
                                return getOrLoadBlock(pos).setInput(pos, inf);
                        if (pos < currPos + currPtr) {