git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH JGIT] Method ignores results of InputStream.skip()

From
Sohn, Matthias <matthias.sohn@sap.com>
Date
Apr 28, 2009, 22:26 UTC
Message-ID
<366BBB1215D0AB4B8A153AF047A287800302A241@dewdfe18.wdf.sap.corp>
In-Reply-To
<366BBB1215D0AB4B8A153AF047A2878002FCE7EA@dewdfe18.wdf.sap.corp>
This method ignores the return value of java.io.InputStream.skip() which can skip multiple bytes.  If the return value is not checked, the caller will not be able to correctly handle the case where fewer bytes were skipped than the caller requested. This is a particularly insidious kind of bug, because in many programs, skips from input streams usually do skip the full amount of data requested, causing the program to fail only sporadically. With buffered streams, however, skip() will only skip data in the buffer, and will routinely fail to skip the requested number of bytes.
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
---
hopefully this time Exchange server doesn't mangle the patch
 .../jgit/transport/BundleFetchConnection.java      |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/BundleFetchConnection.java b/org.spearce.jgit/src/org/spearce/jgit/transport/BundleFetchConnection.java
index 40bf7db..2e2977e 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/BundleFetchConnection.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/BundleFetchConnection.java
@@ -60,6 +60,7 @@
 import org.spearce.jgit.revwalk.RevFlag;
 import org.spearce.jgit.revwalk.RevObject;
 import org.spearce.jgit.revwalk.RevWalk;
+import org.spearce.jgit.util.NB;
 import org.spearce.jgit.util.RawParseUtils;
 
 /**
@@ -139,9 +140,9 @@ private String readLine(final byte[] hdrbuf) throws IOException {
 		while (lf < cnt && hdrbuf[lf] != '\n')
 			lf++;
 		bin.reset();
-		bin.skip(lf);
+		NB.skipFully(bin, lf);
 		if (lf < cnt && hdrbuf[lf] == '\n')
-			bin.skip(1);
+			NB.skipFully(bin, 1);
 		return RawParseUtils.decode(Constants.CHARSET, hdrbuf, 0, lf);
 	}
 
-- 
1.6.2.2.1669.g7eaf8
Previous: Shawn O. PearceNext: Shawn O. Pearce
Message 6 of 9 in “Computation of average could overflow”
  1. Computation of average could overflowSohn, Matthias, Apr 27, 2009
  2. Method invokes inefficient new String(String) constructorSohn, Matthias, Apr 27, 2009
  3. Method invokes inefficient Number constructor; use static valueOf insteadSohn, Matthias, Apr 27, 2009
  4. Method ignores results of InputStream.skip()Sohn, Matthias, Apr 27, 2009
  5. Shawn O. PearceApr 27, 2009
  6. Method ignores results of InputStream.skip()Sohn, Matthias, Apr 28, 2009
  7. Shawn O. PearceApr 27, 2009
  8. Shawn O. PearceApr 27, 2009
  9. Shawn O. PearceApr 27, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.