]> source.dussan.org Git - jgit.git/commitdiff
Fix TransportException when reading bundle 00/64900/1
authorChris Gavin <chris@chrisgavin.me>
Wed, 6 Jan 2016 15:53:22 +0000 (15:53 +0000)
committerMatthias Sohn <matthias.sohn@sap.com>
Thu, 21 Jan 2016 16:07:57 +0000 (17:07 +0100)
When reading a bundle file, commit messages who's oneline format is
longer than 982 characters caused JGit to treat subsequent text in
the commit as a SHA, then throw a TransportException because it's
not a valid SHA.

Now the readLine method will read all the way to the end of the
line, not just the first 1024 characters of it.

Change-Id: If15b491aa9a1e4fd9b8bbed2dd9e6be47a64ccb7
Signed-off-by: Chris Gavin <chris@chrisgavin.me>
org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java

index e53c04b535e5c1e651f4994fa87c8c7c2d689854..8038fa4d31636a4f77b6fed6989ed618c4f756c1 100644 (file)
@@ -161,16 +161,23 @@ class BundleFetchConnection extends BaseFetchConnection {
        }
 
        private String readLine(final byte[] hdrbuf) throws IOException {
-               bin.mark(hdrbuf.length);
-               final int cnt = bin.read(hdrbuf);
-               int lf = 0;
-               while (lf < cnt && hdrbuf[lf] != '\n')
-                       lf++;
-               bin.reset();
-               IO.skipFully(bin, lf);
-               if (lf < cnt && hdrbuf[lf] == '\n')
-                       IO.skipFully(bin, 1);
-               return RawParseUtils.decode(Constants.CHARSET, hdrbuf, 0, lf);
+               StringBuilder line = new StringBuilder();
+               boolean done = false;
+               while (!done) {
+                       bin.mark(hdrbuf.length);
+                       final int cnt = bin.read(hdrbuf);
+                       int lf = 0;
+                       while (lf < cnt && hdrbuf[lf] != '\n')
+                               lf++;
+                       bin.reset();
+                       IO.skipFully(bin, lf);
+                       if (lf < cnt && hdrbuf[lf] == '\n') {
+                               IO.skipFully(bin, 1);
+                               done = true;
+                       }
+                       line.append(RawParseUtils.decode(Constants.CHARSET, hdrbuf, 0, lf));
+               }
+               return line.toString();
        }
 
        public boolean didFetchTestConnectivity() {