Article View: linux.kernel.git
Article #1900[PATCH 5/6] notes: avoid truncating the size of concatenated notes
From: Elia Pinto
Date: Fri, 30 Oct 2026 10:28
Date: Fri, 30 Oct 2026 10:28
62 lines
12986 bytes
12986 bytes
combine_notes_concatenate() reads both notes with odb_read_object(),
which returns their sizes as size_t, but computes the size of the
combined buffer in an "unsigned long". On platforms where that type is
32 bits wide, like Windows, two notes adding up to 4GiB or more give a
small buf_len: we allocate that many bytes and then memcpy() the full
contents of both notes into the buffer, writing far past its end.
The notes can come from a fetched notes ref. Besides notes merges with
the "union" strategy and notes.rewriteMode=concatenate (the default),
the function is also used when loading a notes tree that contains more
than one note for the same object, e.g. at different fanout levels, so
merely displaying such notes is enough to trigger it.
Compute the size as a size_t with st_add3(), and go through
cast_size_t_to_ulong() when passing it to odb_write_object(), whose
length parameter is still an "unsigned long". That makes us die on such
platforms instead of writing a truncated blob, until the write API
learns about size_t, too.
No test, as triggering this needs a platform with a 32-bit "long" and
notes larger than 4GiB.
Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
---
notes.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/notes.c b/notes.c
index ec9c2cb150..05da28b8d4 100644
--- a/notes.c
+++ b/notes.c
@@ -811,8 +811,7 @@ int combine_notes_concatenate(struct object_id *cur_oid,
const struct object_id *new_oid)
{
char *cur_msg = NULL, *new_msg = NULL, *buf;
- unsigned long buf_len;
- size_t cur_len, new_len;
+ size_t cur_len, new_len, buf_len;
enum object_type cur_type, new_type;
int ret;
@@ -839,7 +838,7 @@ int combine_notes_concatenate(struct object_id *cur_oid,
cur_len--;
/* concatenate cur_msg and new_msg into buf */
- buf_len = cur_len + 2 + new_len;
+ buf_len = st_add3(cur_len, 2, new_len);
buf = (char *) xmalloc(buf_len);
memcpy(buf, cur_msg, cur_len);
buf[cur_len] = '\n';
@@ -850,7 +849,7 @@ int combine_notes_concatenate(struct object_id *cur_oid,
/* create a new blob object from buf */
ret = odb_write_object(the_repository->objects, buf,
- buf_len, OBJ_BLOB, cur_oid);
+ cast_size_t_to_ulong(buf_len), OBJ_BLOB, cur_oid);
free(buf);
return ret;
}
--
2.53.0
Technical Details
Message-ID:
<21f5a4e009155e36865f6b01d59a00b644669e41.1793355390.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-73876-linux-kernel-git=dewy.ruReferences:
<cover.1793355390.git.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-73876-linux-kernel-git=dewy.ru
From: gitter.spiros@gmail.com (Elia Pinto)
Newsgroups: linux.kernel.git
Subject: [PATCH 5/6] notes: avoid truncating the size of concatenated notes
Date: Fri, 30 Oct 2026 11:28:38 +0100
Organization: Usenet Network
Message-ID: <21f5a4e009155e36865f6b01d59a00b644669e41.1793355390.git.gitter.spiros@gmail.com>
References: <cover.1793355390.git.gitter.spiros@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="2213003"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:u0vKnRP2pXtp8p9z6UzE4LDTxUo= sha256:D58xac/65BYXunVmnILtezkRwYc6qsv8OQisVU0YQh8=
sha1:ET1BjsXWUJy5UdNCgUmbF/ckUlY= sha256:7QM5+B/uZhXJpc9XRyv9pCN/AeARGN6cwkMN8PshzPs=
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 45C69125C92; Fri, 30 Oct 2026 13:35:44 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.048
X-Spam-Status: No, score=-2.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, 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]
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 MCdAK48Ive_A;
Fri, 30 Oct 2026 13:35:41 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=git+bounces-73876-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 87B99125C8E; Fri, 30 Oct 2026 13:35:33 +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 EF280334DD; Fri, 30 Oct 2026 10:30:02 +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=1793356133;
b=ImwJJfKEfKy33AKbCy3PxievhM6wnnlE4/Vp9XZHcQTGVM7inhy7arOn+MUAJ1zXIEEv
/jIPWWf7n7n+jBFpzUyldBa36LWML09iyoDD3s8j+r4QXezj9bTnV0OP58B1n33nAw4t/
xxW3DmMUsPQpEj8zOUxTluB0cA+PRV9k0X0g68DiLkbpp0J+keVwSHTE4tVwuo1mNl6Es
Q2diYDpI+N0CRQ3kq0Q9XcLvPExVXK1ccxHXInON4Z6cbq539Rv96PoNnNCY0Xrn6DTzs
L4IvZgjYgJOhWsC4J8bQXuU/DmFLwjVmhrJ5L7e8dcVo67OQmFgV683BK4VDYpOLXxA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793356133;
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=2c9dLLipDv7lpOocoSZT6FsRbBQxVRo27HeLtX2INTg=;
b=qT4iGzuiVqAyoUnaI79G2vHz/2K/uk7rg0dBJB1qtIA5cgdKD9oww7wXb59J4R6vcVHl
8qclpRZPM6xeaJWhn1/8EgWTueHfqAFYwOeRk1HQBMACUJPuTZO6T7Cn7Nu0JNef2dBQX
+htKvKuNMA8GnVjWOqKmXMVYTl+WCl20Mi+WNx6Kk7FaC0I9fX23wzzIOkyRDSQjqBO7D
fTTgnCtsr12iDPw48GgSVXewN4t/J3lL65G1Ri5Y1q4qxERqfNeBE6eKlIGnCUOAlZZ3A
cWSSfVBeC2GiUdLKiBnjbsDC/TzJlBmoaK8rudMvQschJq/S6n0RemULMXyu1WpZtFQ==
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=a1aP1kZh;
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 448B060A6F7B;
Fri, 30 Oct 2026 10:28:53 +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=a1aP1kZh
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.47
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1793356132;
b=o96cmMzf36GpchumOyxddlQgQRSVgh8Dro01ZWbWLPMwwh944yqnur8C3obWTA0pJGCr
NlbCWLaIIWSG5sFgMDegOWF2u4irSAYqv+NzHNYgtRu93K5iN8FCY7zNO8pf41/W4jdTY
FiDvg0pGOqAoBDQ/qkayUnfMvehRH6uOJ5STYbYiipXo7BCSueWX7TkZJZmWu2DjKIuHi
m7H4yRjCHELp7RGLJ8he/KSDivSKjolkEqcUiNwNpTXK2csMIzzfmgxENrMlyHWANpCXq
n9bSHsIYDyRQRzmgq4umxIqZnVgkAIimSicnexYJiggkjTq+mRX40z+3LqG3KKTFbEw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793356132;
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=2c9dLLipDv7lpOocoSZT6FsRbBQxVRo27HeLtX2INTg=;
b=Nx6s1w01QEuNhML+uUu7lSXEb8mynALb8XO4Xk/vFZaRMASdp0eabcnprVrTOpWtX5NJ
SwoRjx4oojN9Z/bkZS6dlOhn3uRVs26ZVWW48w513HiaOQi9FVfD0CRXkjK3cJ7964Ojz
2JxAPEb5CAApS6/sbnnu16/GuilJ8pHHtcdf53nqV9BQhcITUdJShpi2ujt/cUBTYfvEu
XTXir8ZMIewH9RqFF2hdKnsBt6J4CodoVnwdxr683F5SdNHNy3mPU7qnTCMwkwVY69vup
i7nilE/V3LkXoE1JCJkVwnhvlPFA8uQlQRJbCB7I9dzXcr2eYd6Xs/DgasSNW6KRw8g==
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=a1aP1kZh;
arc=none smtp.remote-ip=209.85.221.47
X-Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47])
(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 1523060A6F5B
for <git@vger.kernel.org>; Fri, 30 Oct 2026 10:28:51 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1523060A6F5B
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-f47.google.com with SMTP id ffacd0b85a97d-48c4d99c32bso380565f8f.1
for <git@vger.kernel.org>; Fri, 30 Oct 2026 03:28:51 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1793356130; x=1793960930; 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=2c9dLLipDv7lpOocoSZT6FsRbBQxVRo27HeLtX2INTg=;
b=a1aP1kZhStC7EjF0zvWgf+GpVlahJ9r2ou1WuNKy13ZlBtsJigxX03WGZ1Vnhyseeg
UNHHDFjFUho90AFAEuep2YmXOTciJ1sL2cd5SiyG8Vkx6DX2SN12oD7QT2BrxKdoF8m3
c9zskjupC4ANhid3Vi6mWquP8tWcehkT2AiuVXptbEQND/0SWBhPm0kpI6VUTPnFeuwe
8OSxMAGl8/sMbBXI6IFhGTvdRY8QsCUAkDLWAnvtn0lrJtWsMmU5Nw5n/48N00Z7t2eW
0h+r2WQTTYjZ9+TgBSgjdENwVaTS+zUKEKReS9FhqGwL6f41TM8ngAXgpaHCamRzxGdl
mnfg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1793356130; x=1793960930;
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=2c9dLLipDv7lpOocoSZT6FsRbBQxVRo27HeLtX2INTg=;
b=NFGolNv9fz6zFcYwyEIEsoJPY8UbF5iRrlenN53G9P3SCWfCZ4hKulomk15LGVVI6y
fhD3h0FceFhKdGJ2wvmOHdpKtgtdqSY9MHaKCqApjMq8oQ0cJy/LSl0DrjTtu1S9VBsn
o8sU+JpS/lOXTIyC3UsHBJBWH9WeNNm0F4Ihv4iPUHbXWjG2U7g6tQWAnK5pdGi/i7c8
Gs+ZN+JgZ17F2v4d6dXbF3bbe+gubveM6B5GgOxILl4NAkFZWsXmISHJ9oAAnLkFYTW0
z3I9Cwh6tVpDBoEHnhMXcsncuhMYvejr+IG8ANeEBWwyPkJq2JG67o+Fp7Lj+f/FZyjq
O59Q==
X-Gm-Message-State: AFq9FYLcGA0TQ4b82L9IfdQJZTADL0uDEqsm8CyvTW6OkjBgU/TnkBWY
T85a0BtU1qXhaRUsbAoCd4QLoWYyBiHc96skjpqhSy4Z6RnyBBcaUvrA17f/pA==
X-Gm-Gg: AYBFou3bXcRBM1xYvuI3SoemwkrhybOeQZL2ML3orIYvV38Y+s89Uj8nNDz1FYcC1sa
diD5nU4RbG6+TJYlkFEst/qvj3Q6kaeogV5m3KXQNyJSI3P5Wtz5VSSpTY+T3xEUeP4bwoZj6pO
3yvwBQyjaQNxnRKlakk+kVDNSLmuH0S8CzmbBQWR5qanoCP4xdnl0OEwcHqYffNok4zYwnVuapa
9keLz4fR6fyOl+6a367EJoc+xJ0MnpPw8uMnEzPbr0YTeXb/iqYVOrLbrsj7EYD2tBFARAUniCX
E/QqbQIfY4LvJPndZOdyvPtzQ8zK8dprPBsV5ZBG8/wBBy4fQp1kjShVYW56CGXJOMmHV2RGTOw
LL3KG03whkZShzbIfPOZfGXWLckyQSdMxsymSE90s2/bAVHbsLMtVMzJXg40JiJNxRiTPF5uw8i
7IeBYlN5zNtYVTd/M5RG22VGd3jMF/St6NRJyZPi3dxlbFrJbXiOIntrkmt5ozDiVuWb0ZahCjD
cm3PwXrf50OQBs1TzK+Nntm3ZqvVrqST5JWBp3DancTJROVp9TchWgPZLM0Rfb9F9bEwZCEUoA8
6AjTs7uAkrkYXAhzRlWESCxc4bqnHmA6tVja4UDPCPCq/deDug==
X-Received: by 2002:a5d:5d05:0:b0:48e:38e:3102 with SMTP id ffacd0b85a97d-48e6e4f692cmr4566425f8f.29.1793356130237;
Fri, 30 Oct 2026 03:28:50 -0700 (PDT)
X-Received: from ubuntu26lts1.example.com ([205.147.30.18])
by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71b964desm2449445f8f.46.2026.10.30.03.28.49
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Fri, 30 Oct 2026 03:28:49 -0700 (PDT)
X-Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Elia Pinto <gitter.spiros@gmail.com>,
Patrick Steinhardt <ps@pks.im>,
Junio C Hamano <gitster@pobox.com>
X-Mailer: git-send-email 2.53.0
X-In-Reply-To: <cover.1793355390.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