Article View: linux.kernel.git
Article #3616Re: [PATCH v3 1/4] odb: use size_t for the length of objects to write
From: Christian Couder
Date: Mon, 23 Nov 2026 11:39
Date: Mon, 23 Nov 2026 11:39
80 lines
15675 bytes
15675 bytes
On Sat, Oct 31, 2026 at 11:16 AM Elia Pinto <gitter.spiros@gmail.com> wrote:
>
> c6a4629e32 (odb: use size_t for object_info.sizep and the size APIs,
> 2026-06-15) widened the read side of the object database API, and the
> write_object() callback of odb_source already takes a size_t. But
> odb_write_object_ext(), odb_write_object() and odb_source_write_object()
> in front of it, as well as write_loose_object() behind it, still take
> an "unsigned long", which is only 32 bits wide on Windows.
>
> Most callers hand them a size_t from a strbuf or from odb_read_object(),
> which silently gets truncated. The most visible case is index_mem() and
> index_stream_convert_blob(): when "git add" or "git hash-object -w"
> runs a file over 4GiB through a conversion (core.autocrlf, which is on
> by default in Git for Windows, an eol or ident attribute, or a clean
> filter), we write a blob made of the first "size mod 2^32" bytes. The
> index records it with the stat data of the real file, so "git status"
> stays clean and nobody notices until the file is checked out again.
> "git hash-object" without "-w" uses hash_object_file(), which takes a
> size_t, so the two disagree on the object ID of the same file.
>
> Use size_t throughout, including for the size kept by the in-memory
> source.
>
> The existing "hash filtered files over 4GB correctly" test in t1007
> only hashes, so add a variant that writes the object with "git
> hash-object -w" and checks its object ID and that it exists. 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.c | 2 +-
> odb.h | 4 ++--
> odb/source-inmemory.c | 2 +-
> odb/source-loose.c | 2 +-
> odb/source.h | 2 +-
> t/t1007-hash-object.sh | 11 +++++++++++
> 6 files changed, 17 insertions(+), 6 deletions(-)
This patch is very similar to the following patch that I implemented
independently:
https://lore.kernel.org/git/20261117174353.1158905-7-christian.couder@gmail.com/
The changes in the *.c files are the same. The commit message is
arguably better here (as it describes the bugs that are fixed better).
And contrary to my patch, this patch adds a test which is good.
[...]
> diff --git a/t/t1007-hash-object.sh b/t/t1007-hash-object.sh
> index 463b38f990..e76557981d 100755
> --- a/t/t1007-hash-object.sh
> +++ b/t/t1007-hash-object.sh
> @@ -297,4 +297,15 @@ 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 &&
> + git cat-file -e "$(cat actual)"
> +'
It would be nice if all the tests in this test script would clean a
little more after themselves, especially EXPENSIVE tests, so that the
state of the repo doesn't depend on whether GIT_TEST_LONG is set or
not. But the risk here is very low (the ".gitattributes" change only
affects the "big" file), and this is the last test, and other tests
before don't do it. So it could be done in a separate cleanup series.
Technical Details
Message-ID:
<CAP8UFD1JCP-5iWyxxTXqRWZpOXnRHcKfOPa0YHcP6y8z6o4x_g@mail.gmail.com>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-76126-linux-kernel-git=dewy.ruReferences:
<cover.1793352943.git.gitter.spiros@gmail.com> <cover.1793439137.git.gitter.spiros@gmail.com> <4961a1824ad75b6cfa81ab89af650cfc440cff81.1793439137.git.gitter.spiros@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-76126-linux-kernel-git=dewy.ru
From: christian.couder@gmail.com (Christian Couder)
Newsgroups: linux.kernel.git
Subject: Re: [PATCH v3 1/4] odb: use size_t for the length of objects to write
Date: Mon, 23 Nov 2026 12:39:38 +0100
Organization: Usenet Network
Message-ID: <CAP8UFD1JCP-5iWyxxTXqRWZpOXnRHcKfOPa0YHcP6y8z6o4x_g@mail.gmail.com>
References: <cover.1793352943.git.gitter.spiros@gmail.com> <cover.1793439137.git.gitter.spiros@gmail.com>
<4961a1824ad75b6cfa81ab89af650cfc440cff81.1793439137.git.gitter.spiros@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
logging-data="3864503"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:4JiiTgpu7paEyBAfRQvQSyzyvaM= sha256:MtrQZLhcMm2zC59crH7dF5fzv4PkdWOd8wF1tmHdYcs=
sha1:dtHYQgAzPOy3gYGf0WCK/elOk6k= sha256:ZxA+++/wPUr1MdCqUPcvzRkoypwTFaL7iXIPmIT45YE=
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 138C7125D9F; Mon, 23 Nov 2026 14:40:09 +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.249,
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 4tm9Q5qxvgtH;
Mon, 23 Nov 2026 14:40:04 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=git+bounces-76126-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 551E0125DA1; Mon, 23 Nov 2026 14:39:55 +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 716512B489; Mon, 23 Nov 2026 11:39:53 +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=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1795433992;
b=B4O59zENI5nxBzn92uFKfbxzp6/srk9j8h0o2+7nBoNu+3sANLRtC3yEQoa0agTuTdXQ
ogYYDN2clBm9e1eeFEw9W9rodCd0oJCsY4Yfk0yQEkG8vwXDZtRnFW852AHlcBn2IidXA
XJ8tDyzCgU5ViImoP6qLrfhoNVGowPhoHbRW2NByCr5mkoTehqEkWW91KVNjoFoPsJVj3
iq1MVIhX26L2TTZKIBeiSTHsHTbMQ/apkCeoqkGMaKkJLV4XNngqRUuy7ybzt8L7G6rhZ
3C1L5TJY350/2a+PP3xL9rmEt31YFuMnZ122o/ik3fAQXRtx6BO7e/5Dr6qRPBLkFbg==
X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795433992;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:MIME-Version:References:
In-Reply-To:From:Date:X-Gm-Features:Message-ID:Subject:To:Cc:
Content-Type:Content-Transfer-Encoding;
bh=psFn2/GPAVwjtO4Xtdo4NFJM2iXPLp00rrs/phISi0o=;
b=gaugQ0LZG+XfJDdStbh29JTw1dcXggTHcEBbnXJsrs6F5EgrBA4YU8mV7G1bhycE6nvT
V0ZTEdyoh6d0nyYYv9PioYTLScQH2vtRAun/SJyTMnbN67Gbn2UVlu3AtZcoUGbhYZQ2D
iP42LIX9VDbb9AHt1poVG8CpVD/1R4wlyGbdhxRjmgCZZzK5L4M3BiAH548aX+m6gSr1W
nE15pSzSTu1O203LhYIjAzq+w9mLA2wLsQYLTlcCkBnb1YytpJtzUrekomnY0SBvaAByX
3EvuAvm+7c5Yn30q+M7LdmV8ZbhbQ1ncoQG99llY2HnpaIB2lPca5wm65azMfIjzAFg==
X-ARC-Authentication-Results: i=3; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=DeO6lCCw;
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 49CBF606A335;
Mon, 23 Nov 2026 11:39:52 +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=DeO6lCCw
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=74.125.82.41
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1795433991;
b=VExI4fOKZfOQblHyMAulviE5HtHAY5gnVPPW3F7rJSIwEkfAGBFkpQP4/HIv1JPJ8ZYH
vbkjpiCi6eLQiXK0CLIiEuOf/OxCaaN45eU7ldP7UrTJbOweJjebizGzZkXYiCzdc2smg
DCctb5jSz8Xp0MLtQvsLWY63bFy9bSk4asO6NvRQA9Jt4u3+J5m/Ay/5dJ6a0qnTZTGiH
mnlzvUKaVEA9Qa7tGOTAr2T+YvYunrsYjWuf6WLXhA6qt/d3yp1CWKEsrV7zgKvCsWyo6
9HVAH8nWcZwHXGgPfs+lZ6IPOkG0qnYe5JQn13Bt1oWgLFC4ZyaktVdFHnFVocd9wjg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795433991;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:MIME-Version:References:
In-Reply-To:From:Date:X-Gm-Features:Message-ID:Subject:To:Cc:
Content-Type:Content-Transfer-Encoding;
bh=psFn2/GPAVwjtO4Xtdo4NFJM2iXPLp00rrs/phISi0o=;
b=2Jp5JArIHeMov+xIKR1o1NZjt+zAEp/U3W60iWPe6t2TXzkIeW7G4fuSpd7dCDXAnFL8
A4MVSSyMxzJekLAWMrcFzQS6DTQWBkQ2TjEiiPBG96n6Hlrro2R+NZ3F/xOKRiyQzzIlC
amzio6bWMhMmklhx9uD66JXLqZ3U4N6HRiorldulUNW/oHU6xmt1eQB7IIoQzzYrkGhw8
eUAl32NtoVDhrwX/8eR7ZRmMQyKLRXWFo2h5TKaZrbkn+NQBsZ1BNnbIjJEQownmK2paM
4Plk2WSiOvbF78DaVN1jvcolEObwtBIOZKI/hB1A8ypzmH9JsJs00h9PYSozYrjK6lw==
X-ARC-Authentication-Results: i=2; 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=DeO6lCCw;
arc=pass header.oldest-pass=0 smtp.remote-ip=74.125.82.41
X-Received: from mail-dl1-f41.google.com (mail-dl1-f41.google.com [74.125.82.41])
(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 0A845606A31E
for <git@vger.kernel.org>; Mon, 23 Nov 2026 11:39:50 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0A845606A31E
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-dl1-f41.google.com with SMTP id a92af1059eb24-15ea896ddc8so5321158c88.0
for <git@vger.kernel.org>; Mon, 23 Nov 2026 03:39:50 -0800 (PST)
X-ARC-Seal: i=1; a=rsa-sha256; t=1795433990; cv=none;
d=google.com; s=arc-20260327;
b=IDGQQHI6YbW49WG1Pqz3BSp1AZKenPQI6glIqF0WyvSCHS70tpJhr+SGkqieETmudl
Mzk8GzwkmKlKZ5OBw85J5aef2n4tgkzgPn7psIS/g1uOMH9ND1H6J817aDZTRXq8vVl9
egIw7PEVyyaZD4NOE0UVR85LYUvDBI+EJpe5/1CTmTTCRQYUcDrbalLOolWwPTXL5RLj
FTvELDwZ/CeGobWYY5xKfmUilKxLqvGSXtPyMtIYER0UIHpfajd2xtzNl4PSRk44kG2N
Ml6DZNpnTxZrvw2WYXXAYHjF/nyisxZ3lDfLwfJPWox52Zo43VKKyEvxS2XzkmHKrML1
9lJQ==
X-ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327;
h=content-transfer-encoding:cc:to:subject:message-id:date:from
:in-reply-to:references:mime-version:dkim-signature;
bh=psFn2/GPAVwjtO4Xtdo4NFJM2iXPLp00rrs/phISi0o=;
fh=YgaRJzF75Ia0o7riQB7IkokiNn0XQS4TuWBxJ5rQKFw=;
b=T4NKT074w6jgr/fMY0zXrZBsCQwkK+V3oG2fnwz8d8S+q7gXwJWUG8HkJkkI9AQPPP
8607z/8qUv9wJ0LqdofdRKm+hGhl7IF5eZpftCtTOV8vNesGssSayETGzKwGbVRSRRcS
IPdVr0NIums88HnwnLA6ywYI4Mj16AAWx/csYKbKwan1cPkfwuPKicXsSFwAOGXiuD8g
gmWbGIjP89xhN9Pdz47m/aeUowtZJYSDk02qekeyP+5kybqWbn3Yaje8dpDxBLmHc969
k/xA51A+H8R5kQ7q3bfsfVKz+B1Am5sUSnroP6VkIHOjWXCUUwW4Vlw2lC6P50Z8oFtk
XKqQ==;
darn=vger.kernel.org
X-ARC-Authentication-Results: i=1; mx.google.com; arc=none
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1795433990; x=1796038790; darn=vger.kernel.org;
h=content-transfer-encoding:content-type:cc:to:subject:message-id
:date:from:in-reply-to:references:mime-version:from:to:cc:subject
:date:message-id:reply-to:content-type;
bh=psFn2/GPAVwjtO4Xtdo4NFJM2iXPLp00rrs/phISi0o=;
b=DeO6lCCwxgWq0oJr0KqhBp0Mie7HfAPxjofXxq6B8/3aUslpF+Rfn/GKPkttBCyYU2
gN8LSNlj/xrsG9yT/w0k7e28MxsANCfj4CqGpwLIVV94CgaAOZVKl+4ItKE8E+JfypOp
A68vMHfDpFCCKyg+AYkPryGqMQ5UHT2ED7/jjeGlh3Uw1UnhHDyXwR6nYHLcoxRHdxnv
U7tX5LWkyukosQ48ltGhZptuTQwnVnxUG/mZUcB7d/Vx5RFSWlGS+FlGfy2HduEotTg5
tiaPvM7InvU07MDtw6mS8s7XCbnOuI0gqZ1JiLah0F/N2+RPltxY+VshU6Xzdu9x0fng
PPzw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1795433990; x=1796038790;
h=content-transfer-encoding:content-type:cc:to:subject:message-id
:date:from:in-reply-to:references:mime-version:x-gm-gg
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
:content-type;
bh=psFn2/GPAVwjtO4Xtdo4NFJM2iXPLp00rrs/phISi0o=;
b=ySQAS+Ua4vKRR/KssZMjf5RE/6S+lH70/Eb2WMsUUcdMirwbZ2XQEBpSh472409blx
Nnc6gIrWXBwmmWRNVQ6m6WHPBSez6Ikw/IlRHVOKS+K7mE6zHJ6MPmC2ohqyYXAReXTE
fXCmsExaGB74XBqq06YqNG03PepwRXME+t1Wpq01tWX4dS6r61nhMqJGkUv8PUvlt2CB
QaBy93fA73BEdb6zIk6getpFMyJa/OANOsMloq4UPSSUNk6wFwkqaUmRLaHGD24Lz9UT
Yv0DFF9quEF0yy2UyqYoQ83OoboHvtRToBH3zGAivOI5ThYeWYX044kgusrJ9snDCrH6
l4ig==
X-Gm-Message-State: APuU4Z/Yv6Y6a3Sio9sUihzKrXJ68/XWXF2297Ym9i6M5rpc+20qRLLk
AsSzXTX/70AsdewEcCKkWC84MU7saxBW72UkjuKW74DdjiTW+VV+FqDNYpEj72341KbzRZ2V6M1
r0GEb/Ay6xsOa+gF+KZJX7we/pNPLhzk=
X-Gm-Gg: AZFdTZfwM5qnYx7WOb0/J5A4FLSKqyJj8NFAMFYqMoqSPE9eF0nUq54ziFm1mKwJVqD
E/cIibFlLl1Eyzb1B/wyU5AonzRhaAhMRpng6weZpZrT3C6me0dUugLIE9ZyI3CpwLRStz84quM
GF7UJHh+cPSRujyI1SqW/o4oI4E3krl8cAuyBU8Fj0EX0Y7K2g/3RTH/PWeIlfji7jseDvAF5OI
KQwT1OmzQ8fZprldt4DHOq8+GhZrzURR2xj+sUd7nzFjza3zUVJEbN5pjsIVNjCVrKwu2zB7PQR
C5YoBlM6ol4wLX0WtLhfJfB6bSDZMqieXUMptPBhOd51AfYPd/cQKIFXtWi8SFHz4x2+yKR4PVf
vOiYNeDyukHIATY/azzl08a6rCq5B8c7pTYCjwSX8wCwYaWex81D830dAxXex4cFi4fdm20gd5n
Lg9Vt+1/0jQtGQbjw0miA1BqMNqvSP3SjaAkJjj/bBxiwNi+AygpbePud9IAejI89LnAGjqL6ni
Im7fOX/AhN5P03XnMcZdIYqe4dNXZ9t8lV9fDDnyQvraQ==
X-Received: by 2002:a05:7023:a41:b0:1a3:87c8:7efc with SMTP id
a92af1059eb24-1b5569026dcmr9801502c88.39.1795433989986; Mon, 23 Nov 2026
03:39:49 -0800 (PST)
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
X-In-Reply-To: <4961a1824ad75b6cfa81ab89af650cfc440cff81.1793439137.git.gitter.spiros@gmail.com>
X-Gm-Features: Aa3M54rESV1qHdYwpbAmcV7jE2JbDHg-inPeau4Uindcou0wnunO_RoM-efjXYs
X-Cc: git@vger.kernel.org, Patrick Steinhardt <ps@pks.im>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>, Jeff King <peff@peff.net>,
Junio C Hamano <gitster@pobox.com>