aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Strapetz2011-03-21 03:33:40 (EDT)
committerMarc Strapetz2011-03-22 12:33:45 (EDT)
commita327770433ef4495834c382f62aaeea75c847bbf (patch)
tree164b41a31198336e8b65e1b3f60cf66aa2878bd9
parentbf05108d0b1aa7253659237d6848abc72c5e185e (diff)
downloadjgit-a327770433ef4495834c382f62aaeea75c847bbf.zip
jgit-a327770433ef4495834c382f62aaeea75c847bbf.tar.gz
jgit-a327770433ef4495834c382f62aaeea75c847bbf.tar.bz2
Fix: possible IndexOutOfBoundsException in ReflogReaderrefs/changes/83/2783/3
java.lang.IndexOutOfBoundsException at java.nio.ByteBuffer.wrap(ByteBuffer.java:352) at org.eclipse.jgit.util.RawParseUtils.decodeNoFallback(RawParseUtils.java:913) at org.eclipse.jgit.util.RawParseUtils.decode(RawParseUtils.java:880) at org.eclipse.jgit.util.RawParseUtils.decode(RawParseUtils.java:839) at org.eclipse.jgit.storage.file.ReflogReader$Entry.<init>(ReflogReader.java:102) at org.eclipse.jgit.storage.file.ReflogReader.getReverseEntries(ReflogReader.java:183) at org.eclipse.jgit.storage.file.ReflogReader.getReverseEntries(ReflogReader.java:162) Change-Id: I22a18bc7193962e5018c40a75337f9976b585c40
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/ReflogReaderTest.java22
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ReflogReader.java17
2 files changed, 28 insertions, 11 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/ReflogReaderTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/ReflogReaderTest.java
index 64333fc..24c6aeb 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/ReflogReaderTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/ReflogReaderTest.java
@@ -83,6 +83,9 @@ public class ReflogReaderTest extends SampleDataRepositoryTestCase {
static byte[] headLine = "3333333333333333333333333333333333333333 3e7549db262d1e836d9bf0af7e22355468f1717c A U Thor <thor@committer.au> 1243028201 -0100\tbranch: change to HEAD\n"
.getBytes();
+ static byte[] oneLineWithoutComment = "da85355dfc525c9f6f3927b876f379f46ccf826e 3e7549db262d1e836d9bf0af7e22355468f1717c A O Thor Too <authortoo@wri.tr> 1243028200 +0200\n"
+ .getBytes();
+
@Test
public void testReadOneLine() throws Exception {
setupReflog("logs/refs/heads/master", oneLine);
@@ -185,6 +188,25 @@ public class ReflogReaderTest extends SampleDataRepositoryTestCase {
}
@Test
+ public void testReadLineWithMissingComment() throws Exception {
+ setupReflog("logs/refs/heads/master", oneLineWithoutComment);
+ final ReflogReader reader = db.getReflogReader("master");
+ Entry e = reader.getLastEntry();
+ assertEquals(ObjectId
+ .fromString("da85355dfc525c9f6f3927b876f379f46ccf826e"), e
+ .getOldId());
+ assertEquals(ObjectId
+ .fromString("3e7549db262d1e836d9bf0af7e22355468f1717c"), e
+ .getNewId());
+ assertEquals("A O Thor Too", e.getWho().getName());
+ assertEquals("authortoo@wri.tr", e.getWho().getEmailAddress());
+ assertEquals(120, e.getWho().getTimeZoneOffset());
+ assertEquals("2009-05-22T23:36:40", iso(e.getWho()));
+ assertEquals("",
+ e.getComment());
+ }
+
+ @Test
public void testNoLog() throws Exception {
assertEquals(0, db.getReflogReader("master").getReverseEntries().size());
assertNull(db.getReflogReader("master").getLastEntry());
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ReflogReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ReflogReader.java
index 7521430..ea2f738 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ReflogReader.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ReflogReader.java
@@ -88,18 +88,13 @@ public class ReflogReader {
JGitText.get().rawLogMessageDoesNotParseAsLogEntry);
}
who = RawParseUtils.parsePersonIdentOnly(raw, pos);
- int p0 = RawParseUtils.next(raw, pos, '\t'); // personident has no
- // \t
- if (p0 == -1) {
- throw new IllegalArgumentException(
- JGitText.get().rawLogMessageDoesNotParseAsLogEntry);
- }
- int p1 = RawParseUtils.nextLF(raw, p0);
- if (p1 == -1) {
- throw new IllegalArgumentException(
- JGitText.get().rawLogMessageDoesNotParseAsLogEntry);
+ int p0 = RawParseUtils.next(raw, pos, '\t');
+ if (p0 >= raw.length)
+ comment = ""; // personident has no \t, no comment present
+ else {
+ int p1 = RawParseUtils.nextLF(raw, p0);
+ comment = p1 > p0 ? RawParseUtils.decode(raw, p0, p1 - 1) : "";
}
- comment = RawParseUtils.decode(raw, p0, p1 - 1);
}
/**