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

Re: [PATCH 1/3] notes-merge: use size_t in write_buf_to_worktree()

From
Patrick Steinhardt <ps@pks.im>
Date
Nov 18, 2026, 08:25 UTC
Message-ID
<av1g1O5AG7wR7tjb@pks.im>
In-Reply-To
<20261117174353.1158905-6-christian.couder@gmail.com>
On Tue, Nov 17, 2026 at 06:43:55PM +0100, Christian Couder wrote:
Show 15 quoted lines
> The write_buf_to_worktree() function in "notes-merge.c" has an
> `unsigned long` size argument, while its two callers from that same
> file:
> 
> 1. write_note_to_worktree(), and
> 2. ll_merge_in_worktree(),
> 
> both pass a `size_t` to that size argument.
> 
> Since c6a4629e32 (odb: use size_t for object_info.sizep and the size
> APIs, 2026-06-15), the first caller reads the note into a `size_t` size
> before passing it on to write_buf_to_worktree(). On LLP64 platforms
> like 64-bit Windows, where `unsigned long` is 32 bits, a delete/modify
> conflict on a note of 4 GiB or more therefore silently writes a
> truncated note into NOTES_MERGE_WORKTREE.

Heh, this feels like nobody would ever hit such an issue. But fixing it is the right thing regardless of that, of course.

[snip]
> To fix the truncation issue with the first caller and to prepare for
> getting rid of the check, let's convert the size argument in
> write_buf_to_worktree() to a `size_t`.

Makes sense. I've been lamenting about that before, but I really wish that C wasn't so painful to work with in this area. All these implicit casts are just so error-prone.

Show 13 quoted lines
> diff --git a/notes-merge.c b/notes-merge.c
> index d361e70a48..4b010bcfc0 100644
> --- a/notes-merge.c
> +++ b/notes-merge.c
> @@ -310,7 +310,7 @@ static void check_notes_merge_worktree(struct notes_merge_options *o)
>  }
>  
>  static void write_buf_to_worktree(const struct object_id *obj,
> -				  const char *buf, unsigned long size)
> +				  const char *buf, size_t size)
>  {
>  	int fd;
>  	char *path = repo_git_path(the_repository, NOTES_MERGE_WORKTREE "/%s", oid_to_hex(obj));

Looks obviously correct to me. We pass the value to `write_in_full()`, which already accepts a `size_t` as input parameter.

Patrick
Previous: Christian CouderNext: Christian Couder
Message 3 of 7 in “Allow merges with results over 2 GiB on 64-bit Windows”
  1. 0/3 Allow merges with results over 2 GiB on 64-bit WindowsChristian Couder, Nov 17, 2026
  2. 1/3 notes-merge: use size_t in write_buf_to_worktree()Christian Couder, Nov 17, 2026
  3. Patrick SteinhardtNov 18, 2026
  4. 2/3 odb: widen odb_write_object() length to size_tChristian Couder, Nov 17, 2026
  5. Patrick SteinhardtNov 18, 2026
  6. Christian CouderNov 18, 2026
  7. 3/3 xdiff: drop LONG_MAX check on merge result sizeChristian Couder, Nov 17, 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.