]> source.dussan.org Git - jgit.git/commitdiff
Fix IndexOutOfBoundsException when parsing PersonIdent 31/3731/1
authorMarc Strapetz <marc.strapetz@syntevo.com>
Tue, 14 Jun 2011 14:56:48 +0000 (16:56 +0200)
committerMarc Strapetz <marc.strapetz@syntevo.com>
Tue, 14 Jun 2011 14:56:48 +0000 (16:56 +0200)
IndexOutOfBoundsException could occur when parsing
PersonIdent for which no name is present, as part of a
RevCommit (nameB > 0).

org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java
org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java

index 02a78a5baf102c1661d48c81543e39f240bd8c80..7dff6d1ceadbbbe8bc2bead275949df103f7de9c 100644 (file)
@@ -161,6 +161,21 @@ public class RevCommitParseTest extends RepositoryTestCase {
                assertEquals("", c.getShortMessage());
        }
 
+       @Test
+       public void testParse_incompleteAuthorAndCommitter() throws Exception {
+               final StringBuilder b = new StringBuilder();
+               b.append("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n");
+               b.append("author <a_u_thor@example.com> 1218123387 +0700\n");
+               b.append("committer <> 1218123390 -0500\n");
+
+               final RevCommit c;
+               c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
+               c.parseCanonical(new RevWalk(db), b.toString().getBytes("UTF-8"));
+
+               assertEquals(new PersonIdent("", "a_u_thor@example.com", 1218123387000l, 7), c.getAuthorIdent());
+               assertEquals(new PersonIdent("", "", 1218123390000l, -5), c.getCommitterIdent());
+       }
+
        @Test
        public void testParse_implicit_UTF8_encoded() throws Exception {
                final ByteArrayOutputStream b = new ByteArrayOutputStream();
index 9eb32cb997818c241d4c00f07cf3308e5462669e..91184bad617e3c48a211af7d67929fb47e4e83b5 100644 (file)
@@ -717,8 +717,8 @@ public final class RawParseUtils {
                                (emailE >= raw.length - 1 && raw[emailE - 1] != '>'))
                        return null;
 
-               final int nameEnd = emailB - 2 >= 0 && raw[emailB - 2] == ' ' ? emailB - 2
-                               : emailB - 1;
+               final int nameEnd = emailB - 2 >= nameB && raw[emailB - 2] == ' ' ?
+                               emailB - 2 : emailB - 1;
                final String name = decode(cs, raw, nameB, nameEnd);
                final String email = decode(cs, raw, emailB, emailE - 1);