🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.git
Article #1895

[PATCH v2 0/4] use size_t for a few more object and buffer sizes

#1895
From: Elia Pinto
Date: Fri, 30 Oct 2026 09:58
97 lines
15224 bytes
On 64-bit Windows "long" is still 32 bits wide, so a size_t that goes
through an "unsigned long" loses anything above 4 GiB. Like v1, this
series widens three such places: the length taken by the object
write API (patch 1), the allocation size of the word-diff buffers
(patch 2) and the buffer sizes in convert.c (patch 3). Patch 4 is
new. The cover letter of v1 explains how these were found:

  https://lore.kernel.org/git/20261021101640.329990-1-gitter.spiros@gmail.com/

Changes since v1, all following Patrick's review (thanks!):

 - Patch 1 adds the test Patrick asked for. The existing "hash
   filtered files over 4GB correctly" test in t1007 only hashes; the
   new one writes the object with "git hash-object -w" and checks its
   object ID and size. It is EXPENSIVE and SIZE_T_IS_64BIT, like its
   neighbours. Truncating the length to 32 bits in
   odb_write_object_ext() on Linux, to mimic Windows, makes it fail.

 - Patch 4 is new and answers Patrick's question on patch 3: struct
   text_stat still counted in "unsigned", and count_ident() in an
   "int". Note that this one is not specific to LLP64, as "unsigned"
   is 32 bits everywhere; it is in this series because it came up
   in the review and touches the same code. A wrapped counter only
   leads to a wrong decision (e.g. no CRLF conversion for a file with
   exactly 2^32 lone LFs), not to a memory safety problem, because
   the counts are only size hints for strbuf_grow().

 - Rebased on current master; no conflicts.

Elia Pinto (4):
  odb: use size_t for the length of objects to write
  diff: use size_t for the allocation size of word-diff buffers
  convert: use size_t for buffer sizes
  convert: use size_t for text statistics and ident counts

 attr.c                 |  2 +-
 convert.c              | 24 ++++++++++++------------
 diff.c                 |  4 ++--
 odb.c                  |  2 +-
 odb.h                  |  4 ++--
 odb/source-inmemory.c  |  2 +-
 odb/source-loose.c     |  2 +-
 odb/source.h           |  2 +-
 read-cache-ll.h        |  2 +-
 read-cache.c           |  4 ++--
 t/t1007-hash-object.sh | 13 +++++++++++++
 11 files changed, 37 insertions(+), 24 deletions(-)

Range-diff against v1:
1:  0fff9532f9 ! 1:  8fcb9f10f1 odb: use size_t for the length of objects to write
    @@ Commit message
         source.
     
         The existing "hash filtered files over 4GB correctly" test in t1007
    -    only hashes. Running the same with "git hash-object -w" on Windows
    -    shows the problem, but needs another pass over a 5GiB file, so no new
    -    test is added here.
    +    only hashes, so add a variant that writes the object with "git
    +    hash-object -w" and checks both its object ID and its size. Like the
    +    other tests over 4GB, it needs EXPENSIVE and SIZE_T_IS_64BIT. Truncating
    +    the length to 32 bits in odb_write_object_ext(), as happens on Windows
    +    without this patch, makes it fail with a different object ID.
     
         Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
     
    @@ odb/source.h: static inline int odb_source_freshen_object(struct odb_source *sou
      					  enum object_type type,
      					  const struct object_id *oid,
      					  const struct object_id *compat_oid,
    +
    + ## t/t1007-hash-object.sh ##
    +@@ t/t1007-hash-object.sh: test_expect_success EXPENSIVE,SIZE_T_IS_64BIT \
    + 	test_cmp expect actual
    + '
    + 
    ++test_expect_success EXPENSIVE,SIZE_T_IS_64BIT \
    ++		'write filtered files over 4GB correctly' '
    ++	{ test -f big || test-tool genzeros $((5*1024*1024*1024)) >big; } &&
    ++	test_oid large5GB >expect &&
    ++	test_config filter.null-filter.clean "cat" &&
    ++	echo "big filter=null-filter" >.gitattributes &&
    ++	git hash-object -w -- big >actual &&
    ++	test_cmp expect actual &&
    ++	echo $((5*1024*1024*1024)) >expect &&
    ++	git cat-file -s $(cat actual) >actual &&
    ++	test_cmp expect actual
    ++'
    ++
    + test_done
2:  4ab9569f13 = 2:  42d4eae985 diff: use size_t for the allocation size of word-diff buffers
3:  7ea1a566b5 = 3:  88ca2ceb80 convert: use size_t for buffer sizes
-:  ---------- > 4:  84e9e38a3e convert: use size_t for text statistics and ident counts

base-commit: b9e5cff1803ab24582201ef059516eb16014b9d9
-- 
2.53.0
Technical Details
Message-ID: <cover.1793352943.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-73859-linux-kernel-git=dewy.ru
References: <20261021101640.329990-1-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-73859-linux-kernel-git=dewy.ru
From: gitter.spiros@gmail.com (Elia Pinto)
Newsgroups: linux.kernel.git
Subject: [PATCH v2 0/4] use size_t for a few more object and buffer sizes
Date: Fri, 30 Oct 2026 10:58:49 +0100
Organization: Usenet Network
Message-ID: <cover.1793352943.git.gitter.spiros@gmail.com>
References: <20261021101640.329990-1-gitter.spiros@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2208726"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:oz4jcq6I7dzz/WxrE7Y9/tykwWk= sha256:/Nv3/PZMk6cACOMMdSxWZz3S7w2LOdITDMUpOCtlEv0=
	sha1:pDKuXaCbfoyQF9a292Bl2zPfRms= sha256:ggvx8jnuht/wgH+0/XRe9V4dS79dbjdXpWed6bayhyg=
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 A4F66125C92; Fri, 30 Oct 2026 13:10:14 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.047
X-Spam-Status: No, score=-2.047 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, FORGED_GMAIL_RCVD=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,
	URIBL_BLOCKED=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 3BHTL2kZ_fjV;
	Fri, 30 Oct 2026 13:10:10 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=git+bounces-73859-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 99AC2125C8E; Fri, 30 Oct 2026 13:10:01 +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 AE95C25AC2; Fri, 30 Oct 2026 09:59:03 +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=1793354342;
	b=w3boOjfOanWKQ95EPDS9+jdb50IiCW3JbDTA65olHdIuZNB1FN4tAYRaloThAAbYfqL4
	 O6q89H2tXVsD1G2sdOs9Doc4OWBJoN2F4ajWywmFW95D9QAKk39x3aJaO+41/KHe+ykMS
	 ZC3F42awq0ENxPiMvcnNmjcVNST0qdE2d45teHBa8OoHWQ7HTpJbfbe+mXYWBNvF6b87U
	 sdD+XOmP7+Aq99ZEff484iRhwaU5TYc+hVF8SzFl/poAAX+dTsndWUqp/8eLQkOlo0+yD
	 CVnQnqK/cgQMjI2XcJ2tuUW7wSqgd3ZY2imyl2WQr4FNn7atiUsxKfK+lqk89urZ5cw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793354342;
	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=0yuVB2QPGYFxZhqHLqluowKqlNUo1ufQKo3ulDSqXjE=;
	b=fb8b2U66tRRfWpvvBT0z62ZvRaHHoBDAwBW+w1nWSTiU9tBJEfJXPQvSK3kwuX9bqq9k
	 dqwRNw/vpsbY0e1uVXq3+5tRZr1wd/PPAoNAVDkWsVheHh+NDMtF36qNRnTmh4sfVrp/6
	 YOMWhe/vdLvo9nOIPty9tbiFydqaAaTNru7ra6q8XCJJJdspd27/M+CeZRTtQrI94Mz3k
	 seV1eaoCPXWA7uLgqQ9I/VxVr8MxAx8YhNNWwTmeWOHs/EjkyaZokPbP/yMLol6B5IMf6
	 UxQZzV7fPNOIQym+KsPU6qInew+1kOarHDw81Dj8vNxFS8E0zfvO93q7t1Ku2hrcBnw==
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=TFH9TqOK;
	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 AFC18606A322;
	Fri, 30 Oct 2026 09:59:02 +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=TFH9TqOK
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.53
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793354341;
	b=kxCauGl2Nt3wVUyNUSvHesXUkNDHbh8a1o7KwkBr1EFdkXXstMsmgsj3lKiejCAU71IG
	 PbLm3taCsk7g0HvzjOgKSuvbjgi5J/5XqypMa+Ypb6Kz3KKef112oxmshsVcEjXk2wJ60
	 9iUSRFI7TmAzC7MYiVG1VxA36HVeDitGXVwXFm0I/OFLOev22HX/xHhQLviBnuDEhwRy/
	 zvUrXYKVEJ2QJ0Plx9Dx+yFlyvsB7Gqj8cFXo2GIrNfVbzm6gbRXDjvkil+Fbl9qrqHRD
	 XDjalfzOGKHi2dGgYtDc7SAKcnuWdPuOVPt3FHYu7rJI4lQlNKbemDx+4ktylJU+r1Q==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793354341;
	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=0yuVB2QPGYFxZhqHLqluowKqlNUo1ufQKo3ulDSqXjE=;
	b=oc6rF5hQ5WzVThYlm7rxbp3n8w3ziyzeDgh1oL2qUYXJW82FX/bLU8psK4UBj7bqsp05
	 e4/BDg+NN1liappJj2JYLE/Y/wRxVhdRZEG0DUSLy+5iPUy78lPRmJ7+BRWMkvKHj8PXp
	 b9NpIzNImI54p1gCvQb768CCThDZCpx3Ke/dvUW3XXGYaf+tXZHTVan/m7FpyAf9S88m9
	 TtzBQeKk2j+Abu5j9ShXIzlW7ext+96IIZqn+qgXoF0/2RoBSZDRUG4yDXOaYTYRc4ALJ
	 B6+YTrii6EJh7DrxjvFMgICamkJ5DEMhvg/zx4dhqQVmdczBzRME+FAvuCSUtGzoUtA==
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=TFH9TqOK;
	arc=none smtp.remote-ip=209.85.221.53
X-Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53])
	(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 70309606A31D
	for <git@vger.kernel.org>; Fri, 30 Oct 2026 09:59:01 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 70309606A31D
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-f53.google.com with SMTP id ffacd0b85a97d-48df4f540ebso232353f8f.3
        for <git@vger.kernel.org>; Fri, 30 Oct 2026 02:59:01 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20260707; t=1793354340; x=1793959140; 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=0yuVB2QPGYFxZhqHLqluowKqlNUo1ufQKo3ulDSqXjE=;
        b=TFH9TqOKbphuSHhRgZNjbwBfMvr6p1UUI8u7KX8j2kGMlMteqa0VqAU6zf/mWFWB/i
         kWMfguA97AmvzPA2UnT6a37Zx+GLmuAg6AaHEnaWiFGNEObztYhBsRUf/d1gMYUf6GIc
         GYYgiG24bn4xoAnJMmetfPjPyB0AR5cD9e+iiV68gVSVj9i5vfrgcs6na37AaWkoKd8R
         KvuGR4EXgt9dtOFSG5fT+N5LY5nm4czE0owcf796YoacO9oR8njyK0+QhvSF3A4XAk03
         8JNr72+NuD+lHCKOQt6+hHQkhmLuIDioWMziddcant2+u3y2hbGhYi08AOnxzyyunMS1
         +A1g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1793354340; x=1793959140;
        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=0yuVB2QPGYFxZhqHLqluowKqlNUo1ufQKo3ulDSqXjE=;
        b=nWIS16TNgABC7Vj7LyI+APootRZ4RjSB0/CMowPNPRfINJI8yb8Gd/LmnEbcYGO2kT
         QK6/pRbzUsZZLuuSUNU+jQOAOoF+e1KF8KO/9bDbW+yTu+xzUL/yBpJebyR8JX2DfOGg
         cI0/VlOIPdKHB5hmrIw4FOyCaM+wZz1M4RIAhlAzE/a65No+XGyKiPLsX8dxflPZDId+
         JzK2Na791a1RQzm7e3TTpRGU4Efgbl7cvFJHjIFPMSmFKxN/efUfuGkHemuR0AB/OnKC
         ExaPrmy0s0yVpkEdhg3p79D5z4gt19IIeiDzEEHbZzpaAKEnmRiprLZ7t98k/XOGYCUy
         OCPg==
X-Gm-Message-State: AFq9FYLIQ7/vJtojXLg8UCI6oNWGvx0FRL+tAk7KYReBiAqcpWQxNkqe
	02AkveX9NjHPV+phGlY6Pg0d4WBsHBWOyY53jPWFozwg/+mcvzddonTWLDd0Dln5
X-Gm-Gg: AYBFou13BvR1cOfpOJ+0hovOsYjwVuK6kKrnjyGKmHTuHr4eAbpc7y1CRvPSVCeXCJl
	YWFybiyNFyAdyWm4HrUrNipXI33I7UpPBsKxZ8B2c97Qb8JHMSvqpaF8TFpi2i+83vccxRhiVDJ
	CtGjp3hKLxxipBEeVrg1EjFueRRcHVh7Tr9rWAiPOZfxTMGYklx4gHsqmxhtE5Y+hiOVp89CPMa
	jXX+FMvKbbSlVjOAhqDOilKL1aMZ66HB9qXN/X5dI1PGEyWHHlrxH1+adIsjRWnd+RjfgiHCblI
	w/ImbwsSqcYDZ4wBw7XwG/x7PEoy7bTpSFui6Tw+6XcItWXVrGn9sa3CA05pedkadH2+6qUqpln
	u3wAhRBXukG2Nicgy6ymUwsMFjPGY3oO1e5X/3kzsBwY94yxQZcN5XnDmVrQH+mhCmaq+F475ce
	bi+cXxaYXRoKjUww03BQt3+53psNUC2UKfNXg7sbLoqKEOTnhJmhfkzQfE8qLvte/DdDqEiWjG+
	Jo86sip/0I5DQRVZJVmq9n47IGkdTmOnieUGZJUaIjFWPtOeh8Bxm0hIi8J38riSxyzc31l1xqf
	yaIub7BdZ7PvEEUNbg/UCatxKuV8bZlY9MPGeC+CU20uyfi6DA==
X-Received: by 2002:adf:e001:0:10b0:48d:f470:6b3e with SMTP id ffacd0b85a97d-48e6e30722amr3250182f8f.13.1793354339631;
        Fri, 30 Oct 2026 02:58:59 -0700 (PDT)
X-Received: from ubuntu26lts1.example.com ([205.147.30.18])
        by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71b9b54dsm2359421f8f.47.2026.10.30.02.58.58
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Fri, 30 Oct 2026 02:58:59 -0700 (PDT)
X-Cc: Patrick Steinhardt <ps@pks.im>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Jeff King <peff@peff.net>,
	Elia Pinto <gitter.spiros@gmail.com>,
	Junio C Hamano <gitster@pobox.com>,
	Toon Claes <toon@iotcl.com>,
	Shuqi Liang <cheskaqiqi@gmail.com>,
	Karthik Nayak <karthik.188@gmail.com>,
	Ævar Arnfjörð Bjarmason <avarab@gmail.com>
X-Mailer: git-send-email 2.53.0
X-In-Reply-To: <20261021101640.329990-1-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