From 784b24dde151a967229c2f8c2f08b0827709bd4d Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 2 Feb 2010 09:09:26 -0800 Subject: Correctly skip over unrecognized optional dircache extensions We didn't skip the correct number of bytes when we skipped over an unrecognized but optional dircache extension. We missed skipping the 8 byte header that makes up the extension's name and length. We also didn't include the skipped extension's payload as part of our index checksum, resuting in a checksum failure when the index was done reading. So ensure we always scan through a skipped section and include it in the checksum computation. Add a test case for a currently unsupported index extension, 'ZZZZ', to verify we can still read the DirCache object even though we don't know what 'ZZZZ' is supposed to mean. Bug: 301287 Change-Id: I4bdde94576fffe826d0782483fd98cab1ea628fa Signed-off-by: Shawn O. Pearce --- .../dircache/DirCacheCGitCompatabilityTest.java | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'org.eclipse.jgit.test/tst/org/eclipse') diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java index 688fa73598..fa5fea8633 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java @@ -52,6 +52,7 @@ import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; +import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase; import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.ObjectId; @@ -100,6 +101,34 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase { } } + public void testUnsupportedOptionalExtension() throws Exception { + final DirCache dc = new DirCache(pathOf("gitgit.index.ZZZZ")); + dc.read(); + assertEquals(1, dc.getEntryCount()); + assertEquals("A", dc.getEntry(0).getPathString()); + } + + public void testUnsupportedRequiredExtension() throws Exception { + final DirCache dc = new DirCache(pathOf("gitgit.index.aaaa")); + try { + dc.read(); + fail("Cache loaded an unsupported extension"); + } catch (CorruptObjectException err) { + assertEquals("DIRC extension 'aaaa'" + + " not supported by this version.", err.getMessage()); + } + } + + public void testCorruptChecksumAtFooter() throws Exception { + final DirCache dc = new DirCache(pathOf("gitgit.index.badchecksum")); + try { + dc.read(); + fail("Cache loaded despite corrupt checksum"); + } catch (CorruptObjectException err) { + assertEquals("DIRC checksum mismatch", err.getMessage()); + } + } + private static void assertEqual(final CGitIndexRecord c, final DirCacheEntry j) { assertNotNull(c); -- cgit v1.2.3