]> git.99rst.org Git - git.git/commit
object-file: fix closing object stream twice
authorPatrick Steinhardt <redacted>
Fri, 10 Jul 2026 14:54:16 +0000 (16:54 +0200)
committerJunio C Hamano <redacted>
Fri, 10 Jul 2026 21:20:53 +0000 (14:20 -0700)
commitcfd52a74a0cf1a9b0e0ef6b480a45b119d8be4a2
treeebf59655b2e1f8a8c68d772b64f6e2276b089324
parent94f057755b7941b321fd11fec1b2e3ca5313a4e0
object-file: fix closing object stream twice

In 10a6762719 (object-file: adapt `stream_object_signature()` to take a
stream, 2026-02-23), we have refactored `stream_object_signature()` so
that it doesn't create the stream ad-hoc anymore. Instead, callers are
expected to pass in a stream, which allows them to construct the streams
from different sources.

While the stream was previously managed by `stream_object_signature()`,
the full lifecycle is now owned by the caller. Hence, it's the caller's
responsibility to close the stream, and the called function shouldn't do
that anymore.

And while the mentioned commit did drop one call that closed the stream,
there's a second such call that was missed when reading from the stream
fails. The consequence of this can be a double free of the stream.

Fix the bug by dropping that leftover call to `odb_read_stream_close()`.

Note that it was originally discussed whether this should be treated as
a security vulnerability. But there are only two callers: once via
`parse_object_with_flags()`, and once via `verify_packfile()`. Neither
of these callers plays any role on the transport layer, so this issue is
only relevant for objects that are already available via the local
object database. Furthermore, a packfile that is corrupted in this way
would be detected when receiving the packfile, so it's not easy for an
adversary to plant such a packfile, either. Consequently, we decided
that this is not covered as part of our threat model.

Reported-by: xuqing yang <redacted>
Helped-by: Jeff King <redacted>
Signed-off-by: Patrick Steinhardt <redacted>
Signed-off-by: Junio C Hamano <redacted>
object-file.c
t/t1450-fsck.sh
git clone https://git.99rst.org/PROJECT