🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.git
Article #1018

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

#1018
From: Elia Pinto
Date: Wed, 21 Oct 2026 10:16
123 lines
15542 bytes
On 64-bit Windows, "long" is still 32 bits wide. Whenever a size_t
travels through an "unsigned long", anything above 4 GiB is silently
lost. Johannes's js/objects-larger-than-4gb-on-windows work fixed the
read side of the object database, and Peff's jk/xdiff-size_t did the
same for the diff and merge machinery. This series picks up three
places that were left narrow.

 - odb: the write API still takes the object length as unsigned long.
   A large file that is converted before being stored (for example
   with core.autocrlf, which Git for Windows enables by default) can
   reach odb_write_object() with a size_t length above 4 GiB. The
   blob is then written truncated, with no error, and the index
   happily records it.

 - diff: diff_words_fill() grows its buffer with a signed "long"
   allocation size. Its output can be twice its input, and on LLP64
   the growth computation overflows past about 700MiB, which is well
   within what xdiff accepts. In practice Git dies on a huge
   allocation request.

 - convert: the helpers that decide whether a file is binary, has
   CRLF line endings or "$Id$" keywords take an unsigned long length.
   For files over 4GiB they only look at a prefix. In the same area,
   read_blob_data_from_index() narrows its result with
   cast_size_t_to_ulong(), so "git add" with core.autocrlf dies when
   the staged version is that large.

There are no new tests. Each case needs files of several GiB and a
32-bit "long", and the commit messages explain how to reproduce them.

How these were found
--------------------

I wanted a list of all the places where a 64-bit size is narrowed on
Windows, rather than waiting for the next bug report. Linux compilers
cannot see the problem, because there "long" and "size_t" have the
same width. So I analysed the tree as a Windows target instead.

The first step is a compilation database from a real MinGW
configuration. Forcing --target onto a database generated on Linux
does not work well: Linux-only defines leak in, regex.h is missing
from MinGW, and the precompiled header is rejected for the wrong
target. A Meson cross build avoids all of that:

  $ cat mingw64.cross
  [binaries]
  c       = 'x86_64-w64-mingw32-gcc'
  ar      = 'x86_64-w64-mingw32-ar'
  strip   = 'x86_64-w64-mingw32-strip'
  windres = 'x86_64-w64-mingw32-windres'

  [host_machine]
  system     = 'windows'
  cpu_family = 'x86_64'
  cpu        = 'x86_64'
  endian     = 'little'

  $ meson setup build-win --cross-file mingw64.cross \
	-Db_pch=false -Dsane_tool_path=/usr/bin \
	-Dcurl=disabled -Dexpat=disabled -Dpcre2=disabled \
	-Dgettext=disabled -Diconv=disabled -Drust=disabled
  $ meson compile -C build-win

Two of these options are not obvious. Without -Dsane_tool_path,
setup stops because meson.build adds "C:/Program Files/Git/bin" to
the program search path, which is not absolute on a Linux host. And
-Db_pch=false is needed because clang cannot read the precompiled
header that GCC produces. The build only has to get far enough to
generate the headers; link errors do not matter here.

The second step runs clang-tidy over that database with
-Wshorten-64-to-32, for the x86_64-w64-mingw32 target, skipping the
bundled zlib and OpenSSL. One detail cost me a while: with
"-checks=-*", clang-tidy drops compiler warnings unless
clang-diagnostic-shorten-64-to-32 is enabled explicitly. I wrapped
all this in a small script, which also refuses to report "no
findings" when some translation units failed to parse:

  https://github.com/devzero2000/toyscript/blob/main/check_llp64_portability.sh

It is not meant for inclusion. I mention it so that the numbers below
can be reproduced, and in case someone finds it useful.

What the scan shows
-------------------

All 569 translation units were analysed, none failed. There are 1432
64-to-32 truncation warnings, but most of them are not specific to
Windows: about 1200 narrow a size_t to an int, as they do on Linux.
Only 237 have "long" or "unsigned long" as their destination.

Most of those 237 sit on API boundaries that are known and that
commit c6a4629e32 names explicitly: diff, blame, textconv and
fast-import. Others are in tree walking, object parsing and the pack
tools, where an oversized object makes Git die rather than misbehave.
I would like to convert them in later small series, one area at a
time, in the same style as jk/xdiff-size_t.

Johannes, the first patch continues your write-side work. I hope it
does not step on a follow-up you already have in progress.

Elia Pinto (3):
  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

 attr.c                |  2 +-
 convert.c             | 14 +++++++-------
 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 ++--
 10 files changed, 19 insertions(+), 19 deletions(-)


base-commit: 47fdf2208c5b94c8cc01c106b8f7c85efb91c926
--
2.53.0
Technical Details
Message-ID: <20261021101640.329990-1-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-72696-linux-kernel-git=dewy.ru

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-72696-linux-kernel-git=dewy.ru
From: gitter.spiros@gmail.com (Elia Pinto)
Newsgroups: linux.kernel.git
Subject: [PATCH 0/3] use size_t for a few more object and buffer sizes
Date: Wed, 21 Oct 2026 12:16:36 +0200
Organization: Usenet Network
Message-ID: <20261021101640.329990-1-gitter.spiros@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="4106278"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:uZ1wiOWFkgU8EwbYVBOLs5Xu+wM= sha256:IXPbmRosel2aPUxQ6mG/79eTXQYAZYouO2RK+BKW+VY=
	sha1:AC4Y8XjuE+nz1swNnoQArtJPQCc= sha256:3d9jSow86DNX+qqJWC5tIhopj/s3+Iu+fdKyifBPbnY=
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 72C9B110FAA; Wed, 21 Oct 2026 13:21:38 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -1.947
X-Spam-Status: No, score=-1.947 tagged_above=-9999 required=6.31
	tests=[DCC_CHECK=1.1, 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, 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 HuOXhNVDm89h;
	Wed, 21 Oct 2026 13:21:35 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-72696-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 916A4110DD8; Wed, 21 Oct 2026 13:21:26 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id BE442364B9; Wed, 21 Oct 2026 10:16:48 +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=1792577808;
	b=1QeD0aMfTpin3lvDD3FuoeE9re/0vYdEWU3s66LXEn9i3UUAjFCdmvhTn9YlSxLRyzyU
	 DF4IkLWgi+shHMqKbq0hdJ/cKKhPOYHTMAfsi+J1yDbAeNIIl0MWb8InuT/wDIXuHNH3f
	 /TA/Bn0w5hWaj+I965I9iXdSxD4o4TNA064Pw2O79Ymu1GWG8HSzekwTYMfX3w684E7SJ
	 d5+2UZGmArF2mMHdsK6rKOyIm/i9zyAdxYML/Kylow4KrrSvVdPDwRtwGky7MNUiHMvZZ
	 GDhag7QamkKHSfxvPEkblw1vU/LJmQBXQcPbX3Bvn34BHAyHMNkA9zz6sBdneESgV8w==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792577808;
	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:X-Mailing-List:
	 List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe:
	 List-Owner:Precedence:MIME-Version:Content-Transfer-Encoding;
	bh=dB9wt81Sdc2QQqirhgYyQ2GOsMbmS0kEVmX+mIzzW3g=;
	b=SLYUB9ap2qZKeVog0m5wQRqp2v9cBE39KtrUhZ9AN7sEuhqNegxpteSEqEYjCCTamzdD
	 tr5O7ylevt8wC9sC83zpUHzvEY+5svFnSBcvJW1VZpY5P0bnH5Yn2kKv5tfgTXXBYG+9Z
	 i1fwlvMNwfrBITR4ddzm7TLHOGyfwisN832dCt1+uZNBXiNb7sr6MiyPyp4Aduy4zQA7E
	 o4QTAvbX5MMEKbgWDIuL53YO51VZKV+YNsXs8PrwzEaozYUYXf/kojqBIHb4+n+gqL0a4
	 4vpDZsD17TgE81O951EGlyh8B7WWNqmume7o1PPXu/OULJ6UPPi6WPnebvTqvVOvn6Q==
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=20251104 header.b="emdKI5/Y";
	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 6993B606A324;
	Wed, 21 Oct 2026 10:16:48 +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=20251104 header.b=emdKI5/Y
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.45
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1792577807;
	b=lU0B9xwO1uYMotau3HTOJ0n0Na6J5liympyrSjIawF9rICjxA75vD03jFwjfP5ixC2fm
	 jEY6Dy4SxLuvsI+DqHuGpNEOL6Rxte7rXzUUPRPbXBafzc0Erbe8IhwSDxsAL/AJ623uw
	 3YsyT3n1ZfHOMPalNJLfvcH1hLGD0wRx3RDNQ0mPXn07SIEvYDQk4wn5PRQcD5uX2S/Nw
	 LXYOBH9vKtSlQ47KAtifBh4e+6eEvnMpJIFGzPV1Hol8sK4Jkf7lfFyy8ogYz+Lig8SJi
	 F1i1L+CYDjEfwDfgGjFO/b0HgFwKZ6R3GowSmi/tBqvVG3uONp/YtZhwxx1jQlhy44g==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792577807;
	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:MIME-Version:Content-Transfer-Encoding;
	bh=dB9wt81Sdc2QQqirhgYyQ2GOsMbmS0kEVmX+mIzzW3g=;
	b=IMY7Zmus3+y5dzIM+ACiU6yKVNr9R/aFyNFQTUhRSlnMb8a4ddyPeK6h+blWubPNcXBR
	 dAmnCLhtih/IEO9NOSdv6xHU1Kz08sYh1Noa5PLuthOgJ41flS8WZWnxQkDzMa33X1u/y
	 tHTDuqcRvCgKrtweopq7hncrCe3baeWndSQxOUGFMn+Y0q8RXPONeNRK4BIgp4C6FSTbH
	 XgQpF1/499i81hbLE9Jts9tnZCKcbxqMro1GlXI0y9UEQHSnpWDb92P4Q742fx6ntsyzX
	 Z8kt3pkuvq8lOoJxJ3zFZcDFrZDpCpIDcfwUzAGwwplWy3NGHiabHeCBN95sR74jiDA==
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=20251104 header.b="emdKI5/Y";
	arc=none smtp.remote-ip=209.85.221.45
X-Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45])
	(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 23DFF606A334
	for <git@vger.kernel.org>; Wed, 21 Oct 2026 10:16:46 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 23DFF606A334
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-f45.google.com with SMTP id ffacd0b85a97d-48b060ec084so424290f8f.0
        for <git@vger.kernel.org>; Wed, 21 Oct 2026 03:16:46 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20251104; t=1792577805; x=1793182605; darn=vger.kernel.org;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:from:to:cc:subject:date:message-id:reply-to:content-type;
        bh=dB9wt81Sdc2QQqirhgYyQ2GOsMbmS0kEVmX+mIzzW3g=;
        b=emdKI5/YSNN68du1QJccsiVlwOlnV9fwP1u2dME55i8DAIUZkvC5/YVnwccFmVOPyy
         EnjQhQ0Ov0sadQn3dDo0LQR6ipgixfUG6Gsxeq4U6wFwkVb5zVkkidPLvROlRIuLRwGR
         kqJLKrh2oehU6yNpu41io63/iZ0M2h1ubOkSsSZHn5fLjHVEg9FAT171s388mYNtNByE
         UYlar2WS/aWB4rm+eXCNevKs2R4XgEGUwE1Ul66VR9IYGoo+RGjZDJf3iYyCDzbQA0Ge
         CBaXlbVw4x1MgPwtGBPCetCWXeIgRiOakfu/Ay2GgAFydymG8T4xY+wKMHIIgcPzTODy
         bukQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1792577805; x=1793182605;
        h=content-transfer-encoding:mime-version: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=dB9wt81Sdc2QQqirhgYyQ2GOsMbmS0kEVmX+mIzzW3g=;
        b=OA72kNXHLyGX11WyotoP4SmuVwz3GK2DoqzUuEPjhqSkb8TnZnAzEFJdNOVPr54dj0
         RnPLaq2FuCRbwKI0XwEvnrwpZ7b3MsoXXpSHveBXOLnmgS5EbV82ZSCjjOMBcimiESiI
         yJfGgtAY3gbsLCn/Eo6UaSyt7aF/9K3gMm1Rq7FGnOhadmIgwygpcmCfy1gYdodFVu4K
         YmPMMH0xN5iAQJrXL3pAwVfdu1BWSazJd8iLVIT2GWZcY0h7cCBbCUNHLQz7EZDKVVhY
         DjEzO15BdAkz3xLpUQJheltBNKcxSv38mSDGTRPOCoJcgKzwNXPq+QzPC76a/uRg1IqI
         2oVg==
X-Gm-Message-State: AFq9FYJShkflOUyLOmDYpVSWHkcPllu6PXFUoHn+TNj6dnnqTJXZToqT
	h7ndH8mQk3nnZ+jdbRmmQZGYLSXppVcANeotScgEBKVpZihnavUZbmPX9/Km2v/G
X-Gm-Gg: AYBFou3QrIfZ494G/zRHoylimHMTUitg4LahXWUE2fkJJXQmcmBs2Ux84DuXvfQ8XKG
	mjemaTJbhngc8Oq+0PEnpex9oGJBDEgH9PzJV7AZMYtc09titbjQJ2zQA9m6t4oTJCDXHo9r+MZ
	oib8PAFiGEnhtDydE5bAGH4iw31exXmewM0B/+DrfE5huRPOsnQa0xOaH1+lCneBUzk204/MKRG
	VRPztXsjKul1a2OVGhu4VTKsXMiHbfGO9I68ddZX3TQNwBpVxcW5SOqGtiZ+Kh8T/YgGnHDSYtj
	EfbWSOMsOZtkZDiycBUuwQ9ibGLDfESspnhdIAU3cpxqv4yo0oseN+qizhagYCGbSpuKEQMDu9V
	eS/AobHjAujAYvrqTt95xaylOItbss0Rx0fMc0jNN4f7KxO57tyvLq4EYIC4yeiCrS737m7v0Fy
	iXU33Sgx+sG8LqbTQ2F6asic/CXhGczmdCsZ4uyCoC9W40g5B+GnpM1ewdniIRe6qwK7jHwzrWI
	IkudbbIcfoCOkj3Zw7FEvkQoQXOYw42VsUorM8N2yCgrcxYzVhlwfzEQytVPN5GiLlkbmu+E+64
	xivv9ZENB5w=
X-Received: by 2002:a05:6000:2b04:b0:48d:fe88:ffee with SMTP id ffacd0b85a97d-48e264e20c3mr2118536f8f.53.1792577805156;
        Wed, 21 Oct 2026 03:16:45 -0700 (PDT)
X-Received: from ubuntu26lts1.example.com ([151.28.1.33])
        by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e258427cesm4472602f8f.52.2026.10.21.03.16.44
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Wed, 21 Oct 2026 03:16:44 -0700 (PDT)
X-Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Jeff King <peff@peff.net>,
	Elia Pinto <gitter.spiros@gmail.com>
X-Mailer: git-send-email 2.53.0
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