]> git.ipfire.org Git - thirdparty/git.git/commit
object-file: avoid ODB transaction when not writing objects
authorJustin Tobler <jltobler@gmail.com>
Tue, 7 Apr 2026 20:17:30 +0000 (15:17 -0500)
committerJunio C Hamano <gitster@pobox.com>
Wed, 8 Apr 2026 00:32:36 +0000 (17:32 -0700)
commit7d8727ff0b621a9729c2de6a3698063b7b3ba2d6
treeb794801e268ccad9483795ebac5153335c97bf92
parent9a2fb147f2c61d0cab52c883e7e26f5b7948e3ed
object-file: avoid ODB transaction when not writing objects

In ce1661f9da (odb: add transaction interface, 2025-09-16), existing
ODB transaction logic is adapted to create a transaction interface
at the ODB layer. The intent here is for the ODB transaction
interface to eventually provide an object source agnostic means to
manage transactions.

An unintended consequence of this change though is that
`object-file.c:index_fd()` may enter the ODB transaction path even
when no object write is requested. In non-repository contexts, this
can result in a NULL dereference and segfault. One such case occurs
when running git-diff(1) outside of a repository with
"core.bigFileThreshold" forcing the streaming path in `index_fd()`:

        $ echo foo >foo
        $ echo bar >bar
        $ git -c core.bigFileThreshold=1 diff -- foo bar

In this scenario, the caller only needs to compute the object ID. Object
hashing does not require an ODB, so starting a transaction is both
unnecessary and invalid.

Fix the bug by avoiding the use of ODB transactions in `index_fd()` when
callers are only interested in computing the object hash.

Reported-by: Luca Stefani <luca.stefani.ge1@gmail.com>
Signed-off-by: Justin Tobler <jltobler@gmail.com>
[jc: adjusted to fd13909e (Merge branch 'jt/odb-transaction', 2025-10-02)]
Signed-off-by: Junio C Hamano <gitster@pobox.com>
object-file.c
t/t1517-outside-repo.sh