]> git.99rst.org Git - git.git/commit
patch-id: discard hash when done
authorJeff King <redacted>
Thu, 2 Jul 2026 08:04:11 +0000 (04:04 -0400)
committerJunio C Hamano <redacted>
Thu, 2 Jul 2026 16:50:47 +0000 (09:50 -0700)
commit64b69225620a4119e1ee6e02620c56a58dc442fb
tree4d442eeab47a4cc489d4d64f93471c5b96691c33
parent46ba44e1fd6b1a3d71d529f6713821efc26072c9
patch-id: discard hash when done

When computing a patch-id, we have a flush_one_hunk() helper that calls
git_hash_final() on our running hunk git_hash_ctx, and then
reinitializes that context for the next hunk.

When we run out of hunks to look at, we return, discarding the
git_hash_ctx. This can cause a leak if the hash implementation we are
using allocates any memory during its initialization. This includes
OpenSSL >= 3.0, for both SHA-1 and SHA-256. Normally we would not use
SHA-1 here at all, as we only recommend using non-DC implementations for
the "unsafe" variant (and patch-id, though they probably _could_ use the
unsafe variant, were never taught to do so).

But it is certainly a problem for SHA-256, which you can see with:

  make SANITIZE=leak \
       OPENSSL_SHA256=1 \
       GIT_TEST_DEFAULT_HASH=sha256 \
       test

That results in leak failures of 60 scripts, 57 of which are fixed by
this patch (basically anything which runs rebase will hit this case).

Signed-off-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
builtin/patch-id.c
diff.c
git clone https://git.99rst.org/PROJECT