🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.git
Article #3221

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

#3221
From: Elia Pinto
Date: Tue, 17 Nov 2026 10:37
51 lines
12637 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.1794909894.git.gitter.spiros@gmail.com>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-75590-linux-kernel-git=dewy.ru
References: <cover.1793546752.git.gitter.spiros@gmail.com> <cover.1794909894.git.gitter.spiros@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-75590-linux-kernel-git=dewy.ru
From: gitter.spiros@gmail.com (Elia Pinto)
Newsgroups: linux.kernel.git
Subject: [PATCH v2 1/4] csum-file: use size_t for the count passed to hashwrite()
Date: Tue, 17 Nov 2026 11:37:53 +0100
Organization: Usenet Network
Message-ID: <07baad46b153b255b6e70f2597f1bf41b9c48dfd.1794909894.git.gitter.spiros@gmail.com>
References: <cover.1793546752.git.gitter.spiros@gmail.com> <cover.1794909894.git.gitter.spiros@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2304636"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:O6or4BLCySZK2KrviqR8z0LIwus= sha256:UhL/qonOpGImMY9MsHi74w7m0HTAb25DGJxPOCVqj9o=
	sha1:wcFPmtdIkWYFlNL2GvcYLqTpaWM= sha256:ZD6WcAnGt2xFhr2WfQMROO2q10XrPVs1L961+XkTFAU=
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 E72CB114F08; Tue, 17 Nov 2026 13:38:28 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 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.249,
	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 Mcxw_EhaRnCC;
	Tue, 17 Nov 2026 13:38:26 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=git+bounces-75590-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 sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id B6178114F04; Tue, 17 Nov 2026 13:38:16 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id A6FA82BBB1; Tue, 17 Nov 2026 10:38:11 +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=1794911887;
	b=LsGGUhy6evLZIrXqhGmMcr/L9MJ/6e67EHY2/LrE1fhrvpDCznf6kJz2MYPFfwsIddSH
	 xg7uEYCtTVqY0BA4xLALtC6ujRedLHycYepSylXcfwT/u3i+HJjapA0fpAJ05ta4V586o
	 vUkyWyz+yns/AY74uHnvcREonxwy3GWLAeywEQwS6qX1mz3Hhn5fV+8hgi7hpKukLsmRP
	 laSdfqpCWD050oBOv35jMWZtHUnFmB5gi/PdVXY6MLIOxQK1Jtzy8CAVy+zKGr3NHlIUk
	 /W/Ripnl1DVtrnnlpWHglkzVWvTp3fpvUAqblOAk2JOfwKrHLDiSn0cbqLrIMOTRifw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794911887;
	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=pjjdPKTAgKIe89RP07y12JDO4u2eXtmRGfQt4G0kvWd1FRNZX4z3viDj9PI5vLfSDcaE
	 o0izJTfNrzvR6ceCJhXrTkjXCtgv1OvWzSSY4X9C7QFTefZn9ckvTc5XOPox/HXaTH75z
	 IhZOXlwp0P+LpbJpEsYtyrgS50MIddhCOWhm289E6dWr04o4PacYnXw3AzPIzFbrXO3I3
	 SrRuIdOw6EE86E/wdIcJDPDVSniasVjJG5TTzuLzaTFKhc+mQ23veyJZImVoOS53tBXyU
	 eUzftKG8Kntlso/Z5mIA1cPM3iSdNorA/BNTYagMeWWKCoGN8ozlCyvUBZYtqgOz5wA==
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=Byl6cp78;
	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 35A3B606A89C;
	Tue, 17 Nov 2026 10:38:07 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Byl6cp78
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=1794911886;
	b=TrCRkKwM0eEcXJvRCYjJppkm23HAQ19n+hzZXObP6Ka2OAx1Ox7hmSHiBnzM2i6U4Xbr
	 FtM1Efp8uilVINGK9ThlTENrslh1NIVgEWGEUWTXnN9kr7OhnjNgedVhAPWCTTwXxvAbs
	 RELnc2ewmvh5HZNuImv9zEZZ1n9GABCB0AUgOoGarUEHKxxyD2lBKhjjbJG2I3pUO0+dk
	 2PBV0qpJRAdbqdCRE+7G6jXAy+hAzCIXE7hC9Po8tJGx5IryT/Q4f8SUFMVKYfpLWQJYL
	 C0ll2tKC4qVvVD+4TfMNQOFb1F1hid+ecQNFw1KMPcDFcLkSw4hXQ4Kkcy5KeeBkoPg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794911886;
	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=OImeApRxwKIzuWWzvm4AYZad/ZEQCy163aJrFHrC+PB7Mj7sOJwhIaKIXo0jKYN8Ileb
	 5xwG3yM6H77+jON6SRgeXD2WaHNQnBBKBR73DTnkiBXz4+uIqOg3nNppWVFC5BIJHLH0g
	 ygZPwascylVtb2Z3zZSjC6t5jO75mUwMip49QXkvnZAX60Eqc8GOotNY94TH6+Xsi7AEb
	 KVli4kWtq9kgorexBSQRc6+K4rxNwC6AYFjxfuzGdBesZ9HRsoYGW+eq8NfI9FkudKBgd
	 SrWQSzLn6/piNdV3hcWqK0boxFsqTukvhPtK8shHNgxfkxsYn8Wu5faIJ+Zi36VKDaQ==
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=Byl6cp78;
	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 E9307606A32C
	for <git@vger.kernel.org>; Tue, 17 Nov 2026 10:38:05 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E9307606A32C
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-4a5024b3c28so144623f8f.0
        for <git@vger.kernel.org>; Tue, 17 Nov 2026 02:38:05 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20260707; t=1794911884; x=1795516684; 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=Byl6cp785zXTvn/C4FGDylfli8SpQLNf2z2vRe4yi+aYGVmBki6bcXu694YE1fCoLy
         wBik7RyQGOzkSD7e1vIDCyi6a0V/HNmQ0iqsAjybmioA9m9+/gH5xm9+DuABrtAd/d/Y
         y625PfeZbzUY0U3Tf/2UN6XM7Ekxrtfqpo2Iat0UPUxnQpaVkq4khxdpxxcHl+dbqG/1
         rOPJSiGZlrRR/K210MvNF1ipogS1gDTkMYlyIH5JikAMtuKZYizdgRfSu3EZEgtr3Z03
         ytglv2nL9vzgN+6+GDaiboZEkg8JsbImLUsYtjh+kScDAqqofXAC0cQqh9UXNz5Ne99B
         Jyzg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1794911884; x=1795516684;
        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=pUSHzFJSOgJWFtA9uuF6AZzrLS7YwLvnSmeTMcCKw+cTSV8KINkWMy3CcXn1K6dvZo
         sT9j/niW/zkmzgE9HYndR0iQwQ+w22LPL7NRmOnhlzFpdU3rLWd/OmEVSio2fCIDHG1Q
         WA6wxWB14lq1fRqoQUJzHfweFXA1upaFeBtmX0ET/ZYCQC4y8kjIl9iDkBO9vRLqW2tp
         P8wbMgiN9TW2jhnHVuyffC8TkR0a04nVLXbCw6RMJwe+3SMfrG7fcI4SgJ6NJMOAlL11
         uDriM70jR4m7smX6S3dhx/dCFvEPVFKUArvVzy4m6Pm3rUuWYrqY4XixfRxbc/8j5oBo
         HOEg==
X-Gm-Message-State: APuU4Z+1xjRFcN//UZCAVvvMIr4J24Twv8gFINJxLtHFXsPuFbLZOmk/
	ARN7dIp6A8HyPaDK0Gql7Atc0A9F1qfdBBuKBNMrNYfEEC9yOvSaYNYUYLzIjg==
X-Gm-Gg: AZFdTZcPSCoYbP0ebicNPlkZyUUy+Kj/BDH5S2OkLSrMGpDNMy0CMvrzoqTXwIhE360
	zkZanAtulHkvniv6rmNk5h/TJkz5Fiy9XU+tga/qbHG8fdgHQ456eg1Z33BCy9Dq2p9Wxo1srv+
	BYR2VUzsqQTs78koCv+leQEmXEh2wKo11nU+qyZQrd9wxDz7VmWWQ2y1svXr3XZDrcUD8o8kruJ
	IYa6OVz+L+tf3aRVbNRPI8K0+k5Pi9//0IKtEJKmP9/hlinG3HtoczgrFKgnF2ELYQpPgU490tP
	U9Qoz9HdxofCoYXF1s++Rj8gF6ZxyzEO7YxkLmehQA4nzDNOch9flOsfu1w9YJGAGueiJr7k8wT
	AfPTSChrPukag7X7lQ6+21s/tPCviX2LLItafF18qM/fd/9bNFAUFl0aGJnQl1fcTQ9slfC0QK7
	XJfmU5UqdxAtskNFUehIdbtEdmhcktdc6sviLBOatFoE7pHAbiEh98q1xtvd0HOwlh/cj02x+VE
	PTavcslogIZP3cMuR3Vs6pvZvhZtTQIvpqkFgryFMtFyUdgEKM2ioM6USxUASJkihreMiBedlmg
	RvZpgyD0FT/KTJcnAOkWut7Gr2Z9g0fgD6CNxy1kxQD/rOtMpkEsoDNgwsd/96Y=
X-Received: by 2002:a05:6000:2212:b0:493:f271:b622 with SMTP id ffacd0b85a97d-4a3783223aamr4830265f8f.31.1794911884219;
        Tue, 17 Nov 2026 02:38:04 -0800 (PST)
X-Received: from ubuntu26lts1.example.com ([151.31.213.44])
        by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-49c608d10b2sm44715932f8f.44.2026.11.17.02.38.03
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Tue, 17 Nov 2026 02:38:03 -0800 (PST)
X-Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Elia Pinto <gitter.spiros@gmail.com>,
	"brian m. carlson" <sandals@crustytoothpaste.net>,
	Neeraj Singh <neerajsi@microsoft.com>,
	Junio C Hamano <gitster@pobox.com>,
	Patrick Steinhardt <ps@pks.im>
X-Mailer: git-send-email 2.53.0
X-In-Reply-To: <cover.1794909894.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