🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.git
1 messages
1 total messages Started by Christian Couder Tue, 17 Nov 2026 17:43
[PATCH 1/3] notes-merge: use size_t in write_buf_to_worktree()
#3250
Author: Christian Couder
Date: Tue, 17 Nov 2026 17:43
50 lines
12696 bytes
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.

The second caller passes the size of the ll_merge() result, which is a
`size_t` since 81db32ddce (Merge branch 'jk/xdiff-size_t', 2026-10-15).
That size cannot be truncated as since 1c93cc03ea (Merge branch
'kn/safer-mem-arithmetic-in-xdiff', 2026-10-16), xdl_do_merge() errors
out if it is greater than LONG_MAX.

But we want to get rid of that `size > LONG_MAX` check in a following
commit.

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`.

Signed-off-by: Christian Couder <christian.couder@gmail.com>
---
 notes-merge.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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));
-- 
2.56.0
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads