aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java28
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java7
2 files changed, 34 insertions, 1 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java
index 7b31bfa3ad..dce9db572e 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java
@@ -77,10 +77,38 @@ import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.test.resources.SampleDataRepositoryTestCase;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
public class BundleWriterTest extends SampleDataRepositoryTestCase {
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void testEmptyBundleFails() throws Exception {
+ Repository newRepo = createBareRepository();
+ thrown.expect(TransportException.class);
+ fetchFromBundle(newRepo, new byte[0]);
+ }
+
+ @Test
+ public void testNonBundleFails() throws Exception {
+ Repository newRepo = createBareRepository();
+ thrown.expect(TransportException.class);
+ fetchFromBundle(newRepo, "Not a bundle file".getBytes(UTF_8));
+ }
+
+ @Test
+ public void testGarbageBundleFails() throws Exception {
+ Repository newRepo = createBareRepository();
+ thrown.expect(TransportException.class);
+ fetchFromBundle(newRepo,
+ (TransportBundle.V2_BUNDLE_SIGNATURE + '\n' + "Garbage")
+ .getBytes(UTF_8));
+ }
+
@Test
public void testWriteSingleRef() throws Exception {
// Create a tiny bundle, (well one of) the first commits only
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java
index 4b20f6c8b0..84a0972723 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java
@@ -50,6 +50,7 @@ package org.eclipse.jgit.transport;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.BufferedInputStream;
+import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.text.MessageFormat;
@@ -165,9 +166,13 @@ class BundleFetchConnection extends BaseFetchConnection {
while (!done) {
bin.mark(hdrbuf.length);
final int cnt = bin.read(hdrbuf);
+ if (cnt < 0) {
+ throw new EOFException(JGitText.get().shortReadOfBlock);
+ }
int lf = 0;
- while (lf < cnt && hdrbuf[lf] != '\n')
+ while (lf < cnt && hdrbuf[lf] != '\n') {
lf++;
+ }
bin.reset();
IO.skipFully(bin, lf);
if (lf < cnt && hdrbuf[lf] == '\n') {