reftable: drop code for truncated reads

The reftable format is a block based format, but allows for variably
sized blocks. This obviously happens for reflog blocks (which are zlib
compressed), but is also accepted for index blocks: In the spec, this
is motivated as

     To achieve constant O(1) disk seeks for lookups the index must be
     a single level, which is permitted to exceed the file's
     configured block size, but not the format's max block size of
     15.99 MiB.

Hence, when parsing a block, one cannot be sure of its exact size:
after reading a default-size block (eg. 4kb), the block header may
state that the block is in fact larger.

Before, the code would mark the block as `truncated`, noting

     // Its OK during sequential scan for an index block to have been
     // partially read and be truncated in-memory. This happens when
     // the index block is larger than the file's blockSize. Caller
     // will break out of its scan loop once it sees the blockType.

This looks like either

* a remnant of never-implemented functionality. There is no reason to
  ever sequentially scan an index block.

* alluding to sequential scan of the data blocks before the index
  blocks (eg. scanning refs, which ends when we find the first ref index
  block, and we can then ignore the index block).

This comment is followed by code that populates the
restartTbl/restartCnt fields relative to the (possibly truncated)
buffer. If the buffer is truncated, this essentially reads garbage,
leading to OOB array access when using the index block.

Fix this by dropping the truncated logic and issuing a second read if
the first read was short.

Add a test.

We have never observed this failure scenario at Google. We use 64kb
blocksize, which requires us to need fewer index entries. The reftable
spec mentions an Android repo of size 36M. With 64kb blocks, that's
just 562 index entries. Even with historical growth, we are long from
requiring an index whose size exceeds a single block.

When adding the analogous test for seeking refs, there was no failure.
This points to another possibility which is that the code tries to
avoid writing large index blocks for refs.

I did not investigate further which one it is.

Fixes https://bugs.eclipse.org/bugs/show_bug.cgi?id=576250

Bug: 576250
Change-Id: I41ec21fac9e526ef57b3d6fb57b988bd353ee338
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
3 files changed
tree: 7ad4a9862b47965c25e8033f2f762e38e8098e0d
  1. .mvn/
  2. Documentation/
  3. lib/
  4. org.eclipse.jgit/
  5. org.eclipse.jgit.ant/
  6. org.eclipse.jgit.ant.test/
  7. org.eclipse.jgit.archive/
  8. org.eclipse.jgit.benchmarks/
  9. org.eclipse.jgit.coverage/
  10. org.eclipse.jgit.http.apache/
  11. org.eclipse.jgit.http.server/
  12. org.eclipse.jgit.http.test/
  13. org.eclipse.jgit.junit/
  14. org.eclipse.jgit.junit.http/
  15. org.eclipse.jgit.junit.ssh/
  16. org.eclipse.jgit.lfs/
  17. org.eclipse.jgit.lfs.server/
  18. org.eclipse.jgit.lfs.server.test/
  19. org.eclipse.jgit.lfs.test/
  20. org.eclipse.jgit.packaging/
  21. org.eclipse.jgit.pgm/
  22. org.eclipse.jgit.pgm.test/
  23. org.eclipse.jgit.ssh.apache/
  24. org.eclipse.jgit.ssh.apache.test/
  25. org.eclipse.jgit.test/
  26. org.eclipse.jgit.ui/
  27. tools/
  28. .bazelrc
  29. .bazelversion
  30. .gitattributes
  31. .gitignore
  32. .mailmap
  33. BUILD
  34. CONTRIBUTING.md
  35. LICENSE
  36. pom.xml
  37. README.md
  38. WORKSPACE
README.md

Java Git

An implementation of the Git version control system in pure Java.

This project is licensed under the EDL (Eclipse Distribution License).

JGit can be imported straight into Eclipse and built and tested from there. It can be built from the command line using Maven or Bazel. The CI builds use Maven and run on Jenkins.

  • org.eclipse.jgit

    A pure Java library capable of being run standalone, with no additional support libraries. It provides classes to read and write a Git repository and operate on a working directory.

    All portions of JGit are covered by the EDL. Absolutely no GPL, LGPL or EPL contributions are accepted within this package.

  • org.eclipse.jgit.ant

    Ant tasks based on JGit.

  • org.eclipse.jgit.archive

    Support for exporting to various archive formats (zip etc).

  • org.eclipse.jgit.http.apache

    Apache httpclient support.

  • org.eclipse.jgit.http.server

    Server for the smart and dumb Git HTTP protocol.

  • org.eclipse.jgit.lfs

    Support for LFS (Large File Storage).

  • org.eclipse.jgit.lfs.server

    Basic LFS server support.

  • org.eclipse.jgit.packaging

    Production of Eclipse features and p2 repository for JGit. See the JGit Wiki on why and how to use this module.

  • org.eclipse.jgit.pgm

    Command-line interface Git commands implemented using JGit (“pgm” stands for program).

  • org.eclipse.jgit.ssh.apache

    Client support for the ssh protocol based on Apache Mina sshd.

  • org.eclipse.jgit.ui

    Simple UI for displaying git log.

Tests

  • org.eclipse.jgit.junit, org.eclipse.jgit.junit.http, org.eclipse.jgit.junit.ssh: Helpers for unit testing
  • org.eclipse.jgit.ant.test: Unit tests for org.eclipse.jgit.ant
  • org.eclipse.jgit.http.test: Unit tests for org.eclipse.jgit.http.server
  • org.eclipse.jgit.lfs.server.test: Unit tests for org.eclipse.jgit.lfs.server
  • org.eclipse.jgit.lfs.test: Unit tests for org.eclipse.jgit.lfs
  • org.eclipse.jgit.pgm.test: Unit tests for org.eclipse.jgit.pgm
  • org.eclipse.jgit.ssh.apache.test: Unit tests for org.eclipse.jgit.ssh.apache
  • org.eclipse.jgit.test: Unit tests for org.eclipse.jgit

Warnings/Caveats

  • Native symbolic links are supported, provided the file system supports them. For Windows you must use a non-administrator account and have the SeCreateSymbolicLinkPrivilege.

  • Only the timestamp of the index is used by JGit if the index is dirty.

  • JGit requires at least a Java 8 JDK.

  • CRLF conversion is performed depending on the core.autocrlf setting, however Git for Windows by default stores that setting during installation in the “system wide” configuration file. If Git is not installed, use the global or repository configuration for the core.autocrlf setting.

  • The system wide configuration file is located relative to where C Git is installed. Make sure Git can be found via the PATH environment variable. When installing Git for Windows check the “Run Git from the Windows Command Prompt” option. There are other options like Eclipse settings that can be used for pointing out where C Git is installed. Modifying PATH is the recommended option if C Git is installed.

  • We try to use the same notation of $HOME as C Git does. On Windows this is often not the same value as the user.home system property.

Features

  • org.eclipse.jgit

    • Read loose and packed commits, trees, blobs, including deltafied objects.

    • Read objects from shared repositories

    • Write loose commits, trees, blobs.

    • Write blobs from local files or Java InputStreams.

    • Read blobs as Java InputStreams.

    • Copy trees to local directory, or local directory to a tree.

    • Lazily loads objects as necessary.

    • Read and write .git/config files.

    • Create a new repository.

    • Read and write refs, including walking through symrefs.

    • Read, update and write the Git index.

    • Checkout in dirty working directory if trivial.

    • Walk the history from a given set of commits looking for commits introducing changes in files under a specified path.

    • Object transport

      Fetch via ssh, git, http, Amazon S3 and bundles. Push via ssh, git and Amazon S3. JGit does not yet deltify the pushed packs so they may be a lot larger than C Git packs.

    • Garbage collection

    • Merge

    • Rebase

    • And much more

  • org.eclipse.jgit.pgm

    • Assorted set of command line utilities. Mostly for ad-hoc testing of jgit log, glog, fetch etc.
  • org.eclipse.jgit.ant

    • Ant tasks
  • org.eclipse.jgit.archive

    • Support for Zip/Tar and other formats
  • org.eclipse.http

    • HTTP client and server support

Missing Features

There are some missing features:

  • verifying signed commits
  • signing tags
  • signing push

Support

Post questions, comments or discussions to the jgit-dev@eclipse.org mailing list. You need to be subscribed to post. File bugs and enhancement requests in Bugzilla.

Contributing

See the EGit Contributor Guide.

About Git

More information about Git, its repository format, and the canonical C based implementation can be obtained from the Git website.