]> source.dussan.org Git - jgit.git/commit
Cleanup use of java.util.Inflater, fixing rare infinite loops 04/31604/4
authorShawn Pearce <spearce@spearce.org>
Wed, 13 Aug 2014 23:54:22 +0000 (16:54 -0700)
committerShawn Pearce <sop@google.com>
Thu, 14 Aug 2014 19:36:43 +0000 (12:36 -0700)
commit94c4d7eee85d5ffe19d04c5a6e60192430d4fe1e
tree9ee3c8dcbb5d35ea0f93ac045c75feb3f843abe8
parent861f5f649f9beba153557f443db1d5706782961e
Cleanup use of java.util.Inflater, fixing rare infinite loops

The native implementation of inflate() can set finished to return
true at the same time as it copies the last bytes into the buffer.

Check for finished on each iteration, terminating as soon as libz
knows the stream was completely inflated.

If not finished, it is likely input is required before the next
native call could do any useful work. Most invocations are passing
in a buffer large enough to store the entire result. A partial return
from inflate() will need more input before it can continue. Checking
right away that needsInput() is true saves a native call to determine
no bytes can be inflated without more input.

This should fix a rare infinite loop condition inside of inflation
when an object ends exactly at the end of a block boundary, and
the next block contains only the 20 byte trailing SHA-1.

When the stream is finished each new attempt to inflate() returns
n == 0, as no additional bytes were output. The needsInput() test
tries to add the length of the footer block to itself, but then loops
back around an reloads the same block as the block is smaller than
a full block size. A zero length input is set to the inflater,
which triggers needsInput() condition again.

Change-Id: I95d02bfeab4bf995a254d49166b4ae62d1f21346
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlock.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsInserter.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCursor.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java