Article View: linux.kernel.git
Article #3252[PATCH 2/3] odb: widen odb_write_object() length to size_t
From: Christian Couder
Date: Tue, 17 Nov 2026 17:43
Date: Tue, 17 Nov 2026 17:43
115 lines
15083 bytes
15083 bytes
odb_write_object() and odb_write_object_ext() use an `unsigned long`
for their object length argument, while almost everything they pass it
to already uses `size_t`: hash_object_file(), format_object_header(),
convert_object_file(), the `write_object` callback of `struct
odb_source`, and `git_zstream`.
Many callers also pass a `size_t`, often a `strbuf.len`. On LLP64
platforms like 64-bit Windows, where `unsigned long` is 32 bits, such
lengths may silently be truncated.
Since 81db32ddce (Merge branch 'jk/xdiff-size_t', 2026-10-15), the size
of an ll_merge() result is also passed as a `size_t` to
odb_write_object(). It cannot be truncated as since 1c93cc03ea (Merge
branch 'kn/safer-mem-arithmetic-in-xdiff', 2026-10-16), that size
argument cannot be greater than LONG_MAX because xdl_do_merge() errors
out if `size > LONG_MAX`.
But we want to get rid of that `size > LONG_MAX` check in a following
commit.
To fix the possible truncation issues with many callers and to prepare
for getting rid of the check, let's use `size_t` for:
- the length argument of odb_write_object(), odb_write_object_ext(),
the odb_source_write_object() wrapper, and write_loose_object(),
- the size stored in `struct inmemory_object`, which is later
copied back into `size_t` fields (`object_info.sizep` and
`odb_stream.size`).
Signed-off-by: Christian Couder <christian.couder@gmail.com>
---
odb.c | 2 +-
odb.h | 4 ++--
odb/source-inmemory.c | 2 +-
odb/source-loose.c | 2 +-
odb/source.h | 2 +-
5 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/odb.c b/odb.c
index de5be285d3..56a7910b03 100644
--- a/odb.c
+++ b/odb.c
@@ -702,7 +702,7 @@ void odb_assert_oid_type(struct object_database *odb,
}
int odb_write_object_ext(struct object_database *odb,
- const void *buf, unsigned long len,
+ const void *buf, size_t len,
enum object_type type,
struct object_id *oid,
const struct object_id *compat_oid_in,
diff --git a/odb.h b/odb.h
index 857637f980..a09748bdc2 100644
--- a/odb.h
+++ b/odb.h
@@ -634,14 +634,14 @@ enum odb_write_object_flags {
* Returns 0 on success, a negative error code otherwise.
*/
int odb_write_object_ext(struct object_database *odb,
- const void *buf, unsigned long len,
+ const void *buf, size_t len,
enum object_type type,
struct object_id *oid,
const struct object_id *compat_oid,
enum odb_write_object_flags flags);
static inline int odb_write_object(struct object_database *odb,
- const void *buf, unsigned long len,
+ const void *buf, size_t len,
enum object_type type,
struct object_id *oid)
{
diff --git a/odb/source-inmemory.c b/odb/source-inmemory.c
index 75cf29fa9d..c13cffc805 100644
--- a/odb/source-inmemory.c
+++ b/odb/source-inmemory.c
@@ -10,7 +10,7 @@
struct inmemory_object {
enum object_type type;
const void *buf;
- unsigned long size;
+ size_t size;
};
static const struct inmemory_object *find_cached_object(struct odb_source_inmemory *source,
diff --git a/odb/source-loose.c b/odb/source-loose.c
index 50cb388c35..60801e70e8 100644
--- a/odb/source-loose.c
+++ b/odb/source-loose.c
@@ -758,7 +758,7 @@ static int end_loose_object_common(struct odb_source_loose *loose,
static int write_loose_object(struct odb_source_loose *loose,
const struct object_id *oid, char *hdr,
- int hdrlen, const void *buf, unsigned long len,
+ int hdrlen, const void *buf, size_t len,
const time_t *mtime, unsigned flags)
{
int fd, ret;
diff --git a/odb/source.h b/odb/source.h
index 7b56f51b82..8daf5df31c 100644
--- a/odb/source.h
+++ b/odb/source.h
@@ -454,7 +454,7 @@ static inline int odb_source_freshen_object(struct odb_source *source,
* object ID and the compatibility object ID, if non-NULL.
*/
static inline int odb_source_write_object(struct odb_source *source,
- const void *buf, unsigned long len,
+ const void *buf, size_t len,
enum object_type type,
const struct object_id *oid,
const struct object_id *compat_oid,
--
2.56.0
Technical Details
Message-ID:
<20261117174353.1158905-7-christian.couder@gmail.com>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!git+bounces-75623-linux-kernel-git=dewy.ruReferences:
<20261117174353.1158905-5-christian.couder@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!git+bounces-75623-linux-kernel-git=dewy.ru
From: christian.couder@gmail.com (Christian Couder)
Newsgroups: linux.kernel.git
Subject: [PATCH 2/3] odb: widen odb_write_object() length to size_t
Date: Tue, 17 Nov 2026 18:43:56 +0100
Organization: Usenet Network
Message-ID: <20261117174353.1158905-7-christian.couder@gmail.com>
References: <20261117174353.1158905-5-christian.couder@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="2391766"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:wk9RgtiLxASWpJaP+78NBqL0tn8= sha256:0XH0ZSVnQuJW2Kf3dzjD1MEdakXhKhIo4msheGhsb/4=
sha1:y8Oi2VatJ4D52HbEZj8V9gteJUc= sha256:l85LkqDfRcWRwFQhMqCiAhTZFlfhY+MmGK3Bhm1xNjI=
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 31192115027; Tue, 17 Nov 2026 20:45:37 +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 IfQpFo0H-A07;
Tue, 17 Nov 2026 20:45:32 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-75623-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 3869C114FFF; Tue, 17 Nov 2026 20:45:23 +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 E35073E445; Tue, 17 Nov 2026 17:44:31 +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=1794937471;
b=czVb3sRZEELT1lgiBd0kXjP22wp1ze77kU2R9psxcTYpIGM/cvfYdfNwBp0xHPxt/aRs
sCuhs/51Qv+1FXFjwJhe4Ai2Dl5zLfN1IhbfLDus0fuxr057++x1IYmz4gndnjXmGpgyj
R0e/gwBDAK7ohPpkty18C5QDXnoKeD/+oEj9+NpH6iXFv3mQhuPvfQCnIdmiGJBAnQL5w
N8CJoO2pnWjakhOew152TLjd9Hl5xAcA0Fu3tiUX1H4h441i2GeB87d08MbrIhOL0JAIZ
uTAMNr3BMvBhnrtHrT8SbiWl/I08klnYpu++M0q/mZdQI3SxyhlSN8Fgn801enPuNMA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794937471;
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=3kHozEu/3Lj+vitlFPds1A4uvE5DfsvBjiE3QwHMQHc=;
b=dD94YcyZcPJCnWTtGqqrz18KU4dt5Vj/5VquFD83yfzF5sYragFJmuBQWPSezgt8bt2O
qRZgya15wCBN9J5HJZH7/Hp/y5d0Fmz1t79duul3w/j4yavjNEEuWy3LeI3PXTM3HInxB
ylBxhTc8KgQrqNozmhjghmn8WfI/tqVyPpvdcrun+KxLQAC2OW3xJ+JCoh/WnP+uM4ZDL
LfUr4tD0lJZSt0oVx+exC4AIhilVCcEFT77z6SZdC8L1Anpu/rJhyc94rwPrbUjmmYURD
vwVwLeewtoKZm8Kr7wKve0iTuwl7jwz4wVbXyG3dp189Favi0H3vGybgZrfJxas1blQ==
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=Ysh6LgC5;
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 8BE4C606A884;
Tue, 17 Nov 2026 17:44:31 +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=Ysh6LgC5
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.218.49
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1794937470;
b=smIpxCyeY1Z3H+ZqQI6DaA7mJb9JVMK5oySzkL8Mrx4fJT+KnVYD0F/8Ie+5sIHs8hAP
BrIFBb9bqj203k+fIwbBrdpkjCIaVNk7Irati5ptGrKNvTUQepPcSAQ4lpt5UpjLd3q5d
+Pt1/74h1LTpHFjNcCAsSa3UQ8Y6cs+lnY3Mys3oLWTg0x6p9KVCqA+9/EF1IHSq9PxiR
cJcgIh6aEvgqdbjXrjX8UA2zvTFKnjVWqNVUwKZj7/WfHBTa0S3NPLdisGMIWxaz77uwO
NHyS0TMfzNRhoIaTFl+w7EyBSlPisD9S7W17H+8A1dJnQoSHtLHMskZmC71xPXe44mg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794937470;
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=3kHozEu/3Lj+vitlFPds1A4uvE5DfsvBjiE3QwHMQHc=;
b=c9GvX8KjXcA1dG47u3dZB+AdPDUkQyYUeiYhnLjkuxkDZrnUwBNa0EEfq0iJzbi92JPo
ot2k+QJExk61JgQwQG8aITkVSYj2h3cF8Z8jedXNLMIyuFaEeOsfEVSBSR+4/UFNmIqOk
55TcwAYIqC3/lm+ye0ExRUNmmX6LS1xHWcUU6ultCK2aqqXGFq5J2OybAJ8RyMZxf798W
lGbu/zBcK3yJ3Sz3n+rjp37uf4+CCTosEVFiYcIjf/ktAs9ekWNgTm5AngsBru5Xr3fia
xGMDILWT2msH3y0jaAi0Aj8r+jt6kTOhU8TMn3tow1kfLzer3wShYQzXzuB6J9SFVYQ==
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=Ysh6LgC5;
arc=none smtp.remote-ip=209.85.218.49
X-Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49])
(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 64A65606A32A
for <git@vger.kernel.org>; Tue, 17 Nov 2026 17:44:30 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 64A65606A32A
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-ej1-f49.google.com with SMTP id a640c23a62f3a-c50a2efbe1dso794784566b.3
for <git@vger.kernel.org>; Tue, 17 Nov 2026 09:44:30 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1794937469; x=1795542269; 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=3kHozEu/3Lj+vitlFPds1A4uvE5DfsvBjiE3QwHMQHc=;
b=Ysh6LgC5sCs6YJwgCAAgoFWVdeP/jdyYo6XYj1gdYGoN5kVR+/IOrw2yu5MgV/ccqc
GQSVQWwTS8UxMsm+cR26Dx/tphPFAkBbUC1qGSfPfktKTBFvsb3WT89Sfy32hh6mppJq
+BdNpKMmIO3EDRkA4fal7v1M/ZaMFmWG14nMBOAQ/DgurEnX0jwy1dBCnYE/D6BEWTzX
qC5/bqSA1+xAGhsb98YeMT1vly4UVD49DQ9CptGzH7zvQK38F0dHf1hsldktmc2rw9XO
O2kjFmxJi2DL7Z/A/RrjTJaaGra7+chP/RUG9sA7z3sS0womvDUQwiwgazE5+FpiXAbF
UE5g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1794937469; x=1795542269;
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=3kHozEu/3Lj+vitlFPds1A4uvE5DfsvBjiE3QwHMQHc=;
b=yryleoZxdp0NsRnYHYBWqtZ7SBxPVfL1ciBYVDZ8YIrCupcpSOy6xcdMLEmb3vGcau
RgBqZkUsxctVwJa+uUnYJi3UTSd7bpEN78tw7tU2I9aj6jWlj+cZV474hwVRBScuMgX9
onYT+umjKnmEhHFv0NTs5/7TDr2//2KA0pp4+pgK+1Gj7YTCB8Hb5QMm6Y7XhDVebA6S
krhHsUhn9kF/bkhme7+PhKFtajFEdikbafwRKyNIc7GuMOqS2vlzNJ6W4JL5kuVl1NNq
qCUu9X2fQPtNHRQ0mC/uQfUKsW9W46uCO+pNx9+F5Ud9zDX6YgJ3pkgFvcypNO82V4BK
2ylA==
X-Gm-Message-State: APuU4Z/AfJFe1wrVHqmxR0FgYjon2HqE6sXnzQgSFCEFvd0eYKTDODW/
9zGswqxxP9yhanYU2k8ks3FxDvNdDY0mXdHv6Xj0EWLa9Z6bncDoeVhOTUS6QQ==
X-Gm-Gg: AYBFou0ZnkzZSa+hD2E0uFVv6YYPFI2BrKZFk1av0aNoFtDE4hd+zp7lZWdafXgs+zq
Yeu0cZjJEqYZ3EU4+OzsDYeRc+9mM4SJ2acwaEOUTmT70Bqv5RW+Dh0gsq14X1MtrXAwAuAZhJW
FS3EWCTYjXEtkwmlzyJnR19deD9iF2C+LtkjMwl4NPjryMTdjrG/FBLe5lfcF1JxbVjALBWPUMI
D4FcpKy1ttj21v4lgroX9w/MqbnKAILfqy03kJRoIo3wTH1fWWRF59ZlukJL2qV9NVkyWLUffzw
d/ukFFbg5oBhitXWIC+n6bsfY5hxYLbHDTJuE6PcJPLUUyjGKAFR23gifB6ixEyOTcKiY9k1Fc5
5mTlbernbmdiP3s9rDO64khcDwII+1Zk6j/u9ffDom/9uYHK3HZ9/8Q3ly0SA/BLo0bnqdPDkTi
RY4Q/07aUsOJf4bPiyvhBklPPzVN9PMjeOW35UJMMjifhiFIZJBi6AnP/OrkgBYIWw+IAqsbfpG
+shcfAIcq/pQD/BeDAK87p9W8i4glncDkrwzCGilCyL347HVJQd1XiBrceJlX7TuWzC3Q3eNNCX
2IvoaeURCKCSSuhuMGW8mz6KLRQNdvjS0fMgj+jnF//NjkxVxizJcorevAIwKM9oyZc/3lIAqUG
AETTwXlC7Vm5CmSXSgGGt4XzfzoOjZSod6zUzs1je60nHN13AkLltemS8nKJskp55LmqdpJ2j5J
LnTIu2lCIjXiShudXYj2E7zeaMKIaUfvj0T9kYfgg=
X-Received: by 2002:a17:907:608f:b0:c33:923b:ad51 with SMTP id a640c23a62f3a-c509638bf57mr1233844966b.45.1794937468689;
Tue, 17 Nov 2026 09:44:28 -0800 (PST)
X-Received: from christian--20230123--2G7D3 ([62.35.114.108])
by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c510c83fe47sm7947366b.5.2026.11.17.09.44.27
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Tue, 17 Nov 2026 09:44:28 -0800 (PST)
X-Cc: Junio C Hamano <gitster@pobox.com>,
Patrick Steinhardt <ps@pks.im>,
Kaartic Sivaraam <kaartic.sivaraam@gmail.com>,
Jeff King <peff@peff.net>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Christian Couder <christian.couder@gmail.com>
X-Mailer: git-send-email 2.56.1.495.ge87f5c5eed.dirty
X-In-Reply-To: <20261117174353.1158905-5-christian.couder@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