]> source.dussan.org Git - jgit.git/commitdiff
reftable: read file footer in ReftableReader#allRefs 69/149169/5
authorHan-Wen Nienhuys <hanwen@google.com>
Mon, 9 Sep 2019 13:07:25 +0000 (15:07 +0200)
committerHan-Wen Nienhuys <hanwen@google.com>
Wed, 11 Sep 2019 11:01:56 +0000 (13:01 +0200)
allRefs determined the end of the ref block without accounting for
index or log blocks. This could cause other blocks to be interpreted
as ref blocks, leading to "invalid block" error messages.

Change-Id: I7b9323e7d5e0e7d64535b3ec1efd576aed1e9870
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableTest.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/ReftableReader.java

index bd87147479e58af659763f34f0570195b8b08a66..a45548d1e7e23946f6bad73e56122f354f220727 100644 (file)
@@ -566,6 +566,44 @@ public class ReftableTest {
                assertEquals(all, more);
        }
 
+       @Test
+       public void allRefs() throws IOException {
+               ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+               ReftableConfig cfg = new ReftableConfig();
+               cfg.setRefBlockSize(1024);
+               cfg.setLogBlockSize(1024);
+               cfg.setAlignBlocks(true);
+               ReftableWriter writer = new ReftableWriter()
+                               .setMinUpdateIndex(1)
+                               .setMaxUpdateIndex(1)
+                               .setConfig(cfg)
+                               .begin(buffer);
+               PersonIdent who = new PersonIdent("Log", "Ger", 1500079709, -8 * 60);
+
+               // Fill out the 1st ref block.
+               List<String> names = new ArrayList<>();
+               for (int i = 0; i < 4; i++) {
+                       String name = new String(new char[220]).replace("\0", String.format("%c", i + 'a'));
+                       names.add(name);
+                       writer.writeRef(ref(name, i));
+               }
+
+               // Add some log data.
+               writer.writeLog(MASTER, 1, who, ObjectId.zeroId(), id(1), "msg");
+               writer.finish();
+               byte[] table = buffer.toByteArray();
+
+               ReftableReader t = read(table);
+               RefCursor c = t.allRefs();
+
+               int j = 0;
+               while (c.next()) {
+                       assertEquals(names.get(j), c.getRef().getName());
+                       j++;
+               }
+       }
+
+
        @Test
        public void reflogSeek() throws IOException {
                PersonIdent who = new PersonIdent("Log", "Ger", 1500079709, -8 * 60);
index 4f0ff2d1d1796dfd432cb1d607f6ba7d1b25a27e..02c2f5bba834529541079224e7324853e6bc024f 100644 (file)
@@ -169,11 +169,13 @@ public class ReftableReader extends Reftable {
                        readFileHeader();
                }
 
-               long end = refEnd > 0 ? refEnd : (src.size() - FILE_FOOTER_LEN);
-               src.adviseSequentialRead(0, end);
+               if (refEnd == 0) {
+                       readFileFooter();
+               }
+               src.adviseSequentialRead(0, refEnd);
 
-               RefCursorImpl i = new RefCursorImpl(end, null, false);
-               i.block = readBlock(0, end);
+               RefCursorImpl i = new RefCursorImpl(refEnd, null, false);
+               i.block = readBlock(0, refEnd);
                return i;
        }