git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [BUG] v2.45+: git commit -S invalidates signature for non-UTF-8 messages

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Apr 20, 2026, 22:11 UTC
Message-ID
<aeakf0xcjSteTMZp@fruit.crustytoothpaste.net>
In-Reply-To
<4d5d04e2-49c4-4781-a289-f8cf79570643@sunet.se>
On 2026-04-20 at 08:59:05, Kushal Das wrote:
Show 8 quoted lines
> Hi all,
> 
> Every `git commit -S` since v2.45.0 produces a permanently-BAD
> signature when the commit message contains bytes that are not valid
> UTF-8 AND `i18n.commitEncoding` is unset (i.e. the default case).
> Verification fails under both `gpg --verify` and any non-GnuPG signer.
> The failure is deterministic: it happens every time, on every
> non-UTF-8 commit, no card or external tooling needed.

I'm not sure that's a valid configuration. The commit message either needs to be UTF-8 or you need to declare the encoding so Git can convert it.

> My best guess is commit 6206089cbd0b1cb30a017ec904567f040ab4cea0 starting
> this (and I am maybe 100% wrong in identifying the cause).

It does bisect to that commit. I wrote that patch originally, but it got modified and sent upstream by someone else. I'm not sure where it got introduced, though.

Show 7 quoted lines
> In pre-6206089cbd `commit_tree_extended`, `verify_utf8(&buffer)` ran
> BEFORE `sign_with_header(&buffer, sign_commit)`. `verify_utf8` is not
> a simple validator -- it mutates the strbuf in place, replacing
> invalid-UTF-8 bytes with their Latin-1 -> UTF-8 two-byte form. The
> signer therefore saw the transcoded bytes, and the same transcoded
> bytes were then written to the object database. Signer and
> verifier agreed.

The fact that we have a function called `verify_utf8` that does more than verify is a problem. I'll send out a two-patch series in a minute or two that first fixes that to be called `ensure_utf8` and then fixes the issue.

-- 
brian m. carlson (they/them)
Toronto, Ontario, CA
Previous: Kushal DasNext: brian m. carlson
Message 2 of 13 in “[BUG] v2.45+: git commit -S invalidates signature for non-UTF-8 messages”
  1. Kushal DasApr 20, 2026
  2. brian m. carlsonApr 20, 2026
  3. 1/2 commit: name UTF-8 function appropriatelybrian m. carlson, Apr 20, 2026
  4. 2/2 commit: sign commit after mutating bufferbrian m. carlson, Apr 20, 2026
  5. Elijah NewrenApr 22, 2026
  6. brian m. carlsonApr 24, 2026
  7. Elijah NewrenApr 22, 2026
  8. Kushal DasApr 21, 2026
  9. brian m. carlsonApr 21, 2026
  10. D. Ben KnobleApr 22, 2026
  11. 1/2 commit: name UTF-8 function appropriatelybrian m. carlson, Apr 27, 2026
  12. 2/2 commit: sign commit after mutating bufferbrian m. carlson, Apr 27, 2026
  13. Junio C HamanoMay 12, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.