Git development
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Christian Couder <christian.couder@gmail.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
	Kaartic Sivaraam <kaartic.sivaraam@gmail.com>,
	Jeff King <peff@peff.net>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: Re: [PATCH 1/3] notes-merge: use size_t in write_buf_to_worktree()
Date: Wed, 18 Nov 2026 09:25:09 +0100	[thread overview]
Message-ID: <av1g1O5AG7wR7tjb@pks.im> (raw)
In-Reply-To: <20261117174353.1158905-6-christian.couder@gmail.com>

On Tue, Nov 17, 2026 at 06:43:55PM +0100, Christian Couder wrote:
> 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.

> 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

  reply	other threads:[~2026-11-18  8:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 17:43 [PATCH 0/3] Allow merges with results over 2 GiB on 64-bit Windows Christian Couder
2026-11-17 17:43 ` [PATCH 1/3] notes-merge: use size_t in write_buf_to_worktree() Christian Couder
2026-11-18  8:25   ` Patrick Steinhardt [this message]
2026-11-17 17:43 ` [PATCH 2/3] odb: widen odb_write_object() length to size_t Christian Couder
2026-11-18  8:25   ` Patrick Steinhardt
2026-11-17 17:43 ` [PATCH 3/3] xdiff: drop LONG_MAX check on merge result size Christian Couder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=av1g1O5AG7wR7tjb@pks.im \
    --to=ps@pks.im \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=kaartic.sivaraam@gmail.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox