Merge branch 'ps/odb-stream-double-close-fix'

The stream-based object signature verification path has been
corrected to avoid double-closing the stream on read errors.

* ps/odb-stream-double-close-fix:
  object-file: fix closing object stream twice
main
Junio C Hamano 2026-07-21 10:18:36 -07:00
commit 9655cb75ff
2 changed files with 18 additions and 4 deletions

View File

@ -129,11 +129,8 @@ int stream_object_signature(struct repository *r,
for (;;) {
char buf[1024 * 16];
ssize_t readlen = odb_read_stream_read(st, buf, sizeof(buf));

if (readlen < 0) {
odb_read_stream_close(st);
if (readlen < 0)
return -1;
}
if (!readlen)
break;
git_hash_update(&c, buf, readlen);

View File

@ -538,6 +538,23 @@ test_expect_success 'rev-list --verify-objects with bad sha1' '
test_grep -q "error: hash mismatch $(dirname $new)$(test_oid ff_2)" out
'

test_expect_success 'rev-list --verify-objects with truncated loose blob' '
git init truncated-blob &&
(
cd truncated-blob &&
blob=$(test-tool genrandom one 5k | git hash-object -t blob -w --stdin) &&
obj=.git/objects/$(test_oid_to_path $blob) &&

# Truncate the loose blob such that its header can still be
# parsed, but reading the object data fails mid-stream.
test_copy_bytes 64 <"$obj" >obj.tmp &&
mv obj.tmp "$obj" &&

test_must_fail git rev-list --verify-objects "$blob" 2>err &&
test_grep "hash mismatch" err
)
'

# An actual bit corruption is more likely than swapped commits, but
# this provides an easy way to have commits which don't match their purported
# hashes, but which aren't so broken we can't read them at all.