🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.git
Article #2069

[PATCH 1/3] csum-file: use size_t for the count passed to hashwrite()

#2069
From: Elia Pinto
Date: Sun, 01 Nov 2026 15:36
51 lines
12614 bytes
hashwrite() takes the byte count as "uint32_t" on all platforms. When
pack-objects writes the entire compressed buffer of an object in a
single call, which can exceed 4GiB if the object is in memory, poorly
compressible and core.bigFileThreshold is raised accordingly, it writes
only "count mod 2^32" bytes, corrupting the pack.

This was verified using a 16-bit simulation, where "git cat-file" and
"git fsck" failed after "git repack -a -d" with "offset beyond end of
packfile (truncated pack?)".

Make the count parameter of hashwrite() a "size_t". The internal loop
already handles writing in buffer-sized blocks.

Triggering this requires processing an object of 4GiB or more, so no
test is added.

Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
---
 csum-file.c | 2 +-
 csum-file.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/csum-file.c b/csum-file.c
index fe18ee1de3..26aa662637 100644
--- a/csum-file.c
+++ b/csum-file.c
@@ -102,7 +102,7 @@ int finalize_hashfile(struct hashfile *f, unsigned char *result,
 	return fd;
 }
 
-void hashwrite(struct hashfile *f, const void *buf, uint32_t count)
+void hashwrite(struct hashfile *f, const void *buf, size_t count)
 {
 	while (count) {
 		unsigned left = f->buffer_len - f->offset;
diff --git a/csum-file.h b/csum-file.h
index 6ed74d1637..f1c8a9df13 100644
--- a/csum-file.h
+++ b/csum-file.h
@@ -75,7 +75,7 @@ void free_hashfile(struct hashfile *f);
  * Finalize the hashfile by flushing data to disk and free'ing it.
  */
 int finalize_hashfile(struct hashfile *, unsigned char *, enum fsync_component, unsigned int);
-void hashwrite(struct hashfile *, const void *, uint32_t);
+void hashwrite(struct hashfile *, const void *, size_t);
 void hashflush(struct hashfile *f);
 void crc32_begin(struct hashfile *);
 uint32_t crc32_end(struct hashfile *);
-- 
2.53.0
Technical Details
Message-ID: <07baad46b153b255b6e70f2597f1bf41b9c48dfd.1793546752.git.gitter.spiros@gmail.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-74069-linux-kernel-git=dewy.ru
References: <cover.1793546752.git.gitter.spiros@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-74069-linux-kernel-git=dewy.ru
From: gitter.spiros@gmail.com (Elia Pinto)
Newsgroups: linux.kernel.git
Subject: [PATCH 1/3] csum-file: use size_t for the count passed to hashwrite()
Date: Sun,  1 Nov 2026 16:36:49 +0100
Organization: Usenet Network
Message-ID: <07baad46b153b255b6e70f2597f1bf41b9c48dfd.1793546752.git.gitter.spiros@gmail.com>
References: <cover.1793546752.git.gitter.spiros@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2712968"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:0S5aIGjk8szEePPn6Rdff86acHk= sha256:46DmGL9SZUAxEDE7ZTHgparH3uuOOhjTkdN0j9LvgMg=
	sha1:UOeZ4QoRr2W8RZ3w+dLFLIopsNw= sha256:MOTx6YJhJ09bjxwo6bWqZhgeEZUddfIJb67ww8Lh2WQ=
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 8C69A112342; Sun,  1 Nov 2026 18:37:19 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.048
X-Spam-Status: No, score=-3.048 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
	FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id TbN0MSbyg4db;
	Sun,  1 Nov 2026 18:37:16 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=git+bounces-74069-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 99F5CD0948; Sun,  1 Nov 2026 18:37:07 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id E700C2572E; Sun,  1 Nov 2026 15:37:00 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1793547420;
	b=tsg877HwN1cJU2J+QVynZcugkR22oSrtTkyBkvrxxlpDfXOTVBT0AlcZq4Ckzk+9E+VD
	 nBVJjLE03E4Pcstsa9tT+E3DW0hGdsB1lpPcGqRUeI0fJHp0H7Xi3iWP4kyHzCvFKplLf
	 XW7fh8PZriBQYeyx+hkR/cD7RwwxYWN7AYl7oh4AQfgLTq8h78WNpq8mBMLdKnAsVn8vs
	 AshKC9qQYlzjcvDByxgutA8659vAfw0IW/r1Z/0HRHrHCOsRxiWDwhKnTJ0Uurj1VRLFu
	 DgQMMiKSZYmim15ArczGqeNy2BXpx2Kf0iPrrq83mh4gGnuajzNXeMW/CH70uGaE8ZA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793547420;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
	 Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:
	 References:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=dKrpCbQlg9048e0tn+Ci19OTMv+/9H1v9FqHqUqS9uw=;
	b=UibKEiUOknfrIJvQCZ3TbIcDBBZigQfnGW6s5ip6KnrQXU9i2qiKesenjbh/BmJmgCaK
	 v1wZ2NeKQfytO6h/eOaob1DQm48+mpnE2o4nj7tSjv4NSh7sRkbn90wA+fWZJuwGK0U/X
	 Vqd94qRap1eEefB1UdmSY+cn8IyJ20l4Ot//Em6pUElBIWZDE6VX/s0mAwa1GsbiWnzeA
	 vzyDET53Ye98D937iaccIrYPb4eaiUuZd8ttpcd92wT7+Dzget6OkCK23HIsTSpH6Z2CR
	 bPLLWIpD1ryD+6Z8u448wc+YQO0aJCsk0YdYLX/rqjiLpKIS373dSOcToCs7X4Hzwkg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=scxbo0zR;
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id AB878606A327;
	Sun,  1 Nov 2026 15:37:00 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=scxbo0zR
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.48
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793547419;
	b=sYHGoNAHUoJHhKvXswgWmwX69TUmjgzcPJ54oVoT16bAww/4vy5rrXuh6274BGy+t4T8
	 +FQ0zoyqsKPfUkcD6jtB+NnWjFC241q9jXY/kLPns9cZfGcl8ACT6Ah3/LtLZtl8Tw/RI
	 JxkdoFyyxP14/0yyCMBJrKr5/9bf8HKkYA3txPez59ZLc6HFp/Zhm22CheL/YMzluQTRB
	 jvZmC0kjK3TuUuFOxb/mAglNWD0nO/D6Lr2H+HQNh6C8G7dC9gWKTBtj1Xe2O4Io/XOes
	 KGZHQdHh8muun7dkOIKRay7Zk+qjTa7Ffk8E2H1ocaPcKsbJrl3WeRzIY2ZTDCYE9UQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793547419;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:
	 Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Transfer-Encoding;
	bh=dKrpCbQlg9048e0tn+Ci19OTMv+/9H1v9FqHqUqS9uw=;
	b=pdaZ+/aIXKJ1y3ZLkmYdoN2OablkAL4Epqh/70gqHSX+JwqbE1g1UAT8ckuqkwzeTd5v
	 Lh+fwqxh56mgHzriJBylUJaPoVhTFEf0DEJy6bZ4T07olpTCwoFkMMCU+XO+ENGIuzYei
	 szmUsQgS+pIELqSIgPj6kA+2I6LXS1Kv2mqyfLRIBGj8vp+6v/Li0r3JLNbx0rlj/fUAj
	 4tK9t9Q848Bu3TBQCdlnlhBbLafK4SmBe/pVFmLJmd8aZ9GB6fgqoYbqJos5Oiz6Cvhkc
	 VJBbPax6uoi1diqgl1ITfYiP+VatTAOiLUr86RXOaOJAMUmW5rXE5aY2GE2jFTdmaLw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=scxbo0zR;
	arc=none smtp.remote-ip=209.85.221.48
X-Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 77B2B606A32C
	for <git@vger.kernel.org>; Sun,  1 Nov 2026 15:36:59 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 77B2B606A32C
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-48c45111bebso902452f8f.0
        for <git@vger.kernel.org>; Sun, 01 Nov 2026 07:36:59 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20260707; t=1793547418; x=1794152218; darn=vger.kernel.org;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:from:to:cc:subject:date
         :message-id:reply-to:content-type;
        bh=dKrpCbQlg9048e0tn+Ci19OTMv+/9H1v9FqHqUqS9uw=;
        b=scxbo0zRuL7JCXLpjelhhJevUwnnLqgu3jXHIxS5DI70Ui3EjyXnYZ6GrwMqI/CLQu
         MNFdcpfYeHDdjuSR/QxjPDc+SX3y1ygE/97QxN6ZtL7jIGdkF+MkyjBRRNK9Ural3gSQ
         SVbdvWm4Tf0eQH2YgjsSBcfnj4tYRjP4UZvN3zvhVGuEHDrBjXeTm5Ed7hkJVLBjPynO
         yZ2kR9U8e+e71hdr/d6mb0igyZ9V5wX3CLJND1q5O0a5hjbfk2QwbIha3CuyojDNgxWd
         /OSWpq69ReOVyotF7IO8ts7QX/fmMWxr9R2iJKvyjmFBhLN9yLYDTzbPc2Z/B+F9ZV5Y
         b7pQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1793547418; x=1794152218;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from
         :to:cc:subject:date:message-id:reply-to:content-type;
        bh=dKrpCbQlg9048e0tn+Ci19OTMv+/9H1v9FqHqUqS9uw=;
        b=eWU0bzfNnY6Rt01NCPb8iB0py55HXiBUIBlT7tpsx8jgBxAQomasGDgM3qFxWw7W6s
         9Zpo3j5aXOC92ki/3KbV1HTUdqGK+os/8ZX6yPsi7uLlMyc4x+SQkcjq9F6hxPT7qxA2
         eVBfFlG9prilct9iZIM14wVZYzZOf1jVuZJEmcQWS9zggr5XRuZnL3smmWqBf6Nt38PJ
         egkD5//noKGkLQGAAeJVpfJDjvhXx4rgB3WXAqeP5Qbc7E2n1xhoGwM9ateOBMbpLZ51
         vEHbMhQ9Mp2MTF+tOmcT9B4N3R2ONuTXp83Zn8EbAuPc4NdrxHhxJ3mINW3i1ZZgoW33
         VPZQ==
X-Gm-Message-State: APuU4Z/Zh7IiSxwcNNSmNxXwS9LZjJl8BX0vvdIfgzQJ1yBOk+JlnOXB
	TrK/EgnPgWfrBLjM9CBALNdE5sXwBR7ldwFfYbYGeOZcqQpds7sjaY5DwiYhTTwP
X-Gm-Gg: AYBFou1WEfmEGI6lqfr+8W+fxSl+RQ+MxHTfZTfeNz2Jmg4NYxEQk56NfrUFJ7Ii5Rx
	mFURqv20gGEewrHMh2Lfy4YQ2MEwdZyPW2bIaHDxa06HfRz5NepAvvqZUaDi1+Np4ayYae4nlVT
	nWY+VmaRwH9qVLshDI5TD13CH/acBFOpoZZ3qBRwKIOXziQN8kgrMCe/w4y2OVf+G8BiA6TbUUS
	0cRx/BRqjjGoqvuYRg5spTkFLPNVfLfaizRDFh0KiMgdqsu9LQebOCOGe6m3UR1nqZIHp/Ux1ZS
	fLvmJnicBMC2ELtbKdsg4rKFapsluhsZTnlVY0oTRnjqbugjmvgCeDUS2QkiuM7OSrg2S8paucj
	GMq6AYCehMgUF4b9rxDcojig4FQ3nzrz0Cc0xJoBE6yQkoh8/Ud75Is47ePTnIwqUnj5RQbOdVM
	Xvh63a9FhiUG8LPPIEZZLrmpQj+l+puxholBqsb6ZKYpFNs8hd7tQ7WC6Z1h1Ts4JsiN+WSPK5O
	kCponTLHaOQeYQk/Ghc54fPUS54ytkPcvp9pcDbcmR4FwTtPwA3WKrflCi2VPiqos+NU2GmwJ+C
	FhHu55m9e5uQi1SKuPqpCFYk+WuDLIMvcqpfAb+Ehc/sxMF6RmkiYRULWMAsQW4=
X-Received: by 2002:a05:6000:128b:b0:48c:69bd:e971 with SMTP id ffacd0b85a97d-48e6e307437mr12635170f8f.16.1793547417626;
        Sun, 01 Nov 2026 07:36:57 -0800 (PST)
X-Received: from ubuntu26lts1.example.com ([151.31.213.44])
        by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71b7246fsm14908450f8f.19.2026.11.01.07.36.57
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Sun, 01 Nov 2026 07:36:57 -0800 (PST)
X-Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Elia Pinto <gitter.spiros@gmail.com>,
	Neeraj Singh <neerajsi@microsoft.com>,
	Junio C Hamano <gitster@pobox.com>,
	Patrick Steinhardt <ps@pks.im>,
	"brian m. carlson" <sandals@crustytoothpaste.net>
X-Mailer: git-send-email 2.53.0
X-In-Reply-To: <cover.1793546752.git.gitter.spiros@gmail.com>
X-Mailing-List: git@vger.kernel.org
X-List-Post: <mailto:git@vger.kernel.org>
X-List-Help: <mailto:git+help@vger.kernel.org>
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:git+owner@vger.kernel.org>
X-Precedence: list