Browse Source

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 <thomas.wolf@paranor.ch>
stable-5.4
Thomas Wolf 6 years ago committed by David Pursehouse
parent
commit
55966dc592
  1. 28
      org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java
  2. 7
      org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java

28
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

7
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') {

Loading…
Cancel
Save