From 55966dc592b2e45596b8f041680b5e73f616b4ad Mon Sep 17 00:00:00 2001 From: Thomas Wolf Date: Thu, 17 Jan 2019 23:04:46 +0100 Subject: Handle premature EOF in BundleFetchConnection BundleFetchConnection.readLine() must abort on EOF, otherwise it gets stuck in an endless loop. Bug: 543390 Change-Id: I4cb3428560277888af114b928950d620bb6564f9 Signed-off-by: Thomas Wolf --- .../eclipse/jgit/transport/BundleWriterTest.java | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'org.eclipse.jgit.test/tst/org/eclipse') 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 -- cgit v1.2.3