Article View: linux.kernel.git
Article #1901[PATCH 4/6] cat-file: use size_t for the length passed to batch_write()
From: Elia Pinto
Date: Fri, 30 Oct 2026 10:28
Date: Fri, 30 Oct 2026 10:28
48 lines
12585 bytes
12585 bytes
batch_write() takes the length of the data as an "int", but its callers
pass the size of whole objects as returned by odb_read_object() or
filter_object(), which is a size_t. For an object between 2GiB and
4GiB the length wraps to a negative value, which fwrite() and
write_or_die() then see as an enormous size_t. We happily write the
object and then keep going past the end of the buffer, sending whatever
memory follows to stdout, until we hit an unmapped page and die with
"write error: Bad address". Objects of 4GiB and more are truncated
instead, which desynchronizes the --batch output.
This affects all platforms, not only those with a 32-bit "long". It can
be triggered with "--batch" on any non-blob object, or on blobs with
--filters or --textconv, as blobs are otherwise streamed. For example:
blob=$(test-tool genzeros $((3 * 1024 * 1024 * 1024)) |
git hash-object -w --stdin) &&
echo "$blob big" |
git cat-file --batch="%(objectname) %(rest)" --filters >out
fails with "write error: Bad address"; with stdout going to /dev/null,
strace shows write() being called on addresses far beyond the end of the
3GiB buffer. There is no test, as it would need several GiB of memory
and disk.
Both fwrite() and write_or_die() take a size_t already, so just change
the parameter type.
Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
---
builtin/cat-file.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 8870a210ec..c846fe3116 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -425,7 +425,7 @@ static void expand_format(struct strbuf *sb, const char *start,
}
}
-static void batch_write(struct batch_options *opt, const void *data, int len)
+static void batch_write(struct batch_options *opt, const void *data, size_t len)
{
if (opt->buffer_output) {
if (fwrite(data, 1, len, stdout) != len)
--
2.53.0
Technical Details
Message-ID:
<b2083632a1373b53380ead18ec32ca302143feec.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-73875-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-73875-linux-kernel-git=dewy.ru
From: gitter.spiros@gmail.com (Elia Pinto)
Newsgroups: linux.kernel.git
Subject: [PATCH 4/6] cat-file: use size_t for the length passed to batch_write()
Date: Fri, 30 Oct 2026 11:28:37 +0100
Organization: Usenet Network
Message-ID: <b2083632a1373b53380ead18ec32ca302143feec.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="2213092"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:t/umkMmVILSS5w4uUjIUywPXK1E= sha256:X+d3cqqyPxSfZceJemvWHc9b1ATOBn0/0Ms5YY3pGGU=
sha1:AWvzS0mmcWplZhLMBawmXzT/cw4= sha256:JGDITHejgoX7oUTuKIZuQcNmkoo5HmSyrxTPpSzbAUo=
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 46CE3125C92; Fri, 30 Oct 2026 13:36:22 +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.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 S4DPEaqPcf6M;
Fri, 30 Oct 2026 13:36:19 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=git+bounces-73875-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 A1FA8125C8F; Fri, 30 Oct 2026 13:36:11 +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 4A3EC2C8A8; Fri, 30 Oct 2026 10:29:59 +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=1793356132;
b=o/NlcBVlvfayH9aecpCdaAa28RCzPxCD49WD8D8nBYIfwgUlvyG1erO3GxI0XPcL/gpS
cdEV1nMHs/ET4MxPeuG7D52k9Q0WR4u84yhS15zPpqfHtx0g2Bi5CIIx2+c1W1wT6Tnl2
IpLSMSVS2ePdumNkDI3W1kkp3pj/whYdhoRclVib9yNbomFy42ujvzg5KMwRottYuz77f
KrTE4cfrZxyk0tBGYCjsJchTzK9ysG+nvx76pnTIpXgueiFcHRrMTfdKl6zUCouaAPR3W
PbeGIcnEdLuP2maJxDAcCLr7kNcCOVgLWMAiO2n503WaSq1DpKdqRxNQiii0ffsKv6w==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793356132;
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=aeZlgdld8Mlenh+df9G4lQ3t/qfooZFG5zrAZBl7IVQ=;
b=aWjlWI+n1O8GhVGN3DR9fTY2NdFzbqUmElUkV+hh2WH7y6tPA2eSdFFIyKn01D7nbiaQ
i6CDzRmiOvTQH+x4C654XkSTUyb4fF3Sip1z9qPmH1k2w9lNsvn3j/XEPTvbv6bVeX6ro
E0rR7C8Yke894jTuw1tcq93ViHegMvEsJKPcYSy5/gLX/ME60b4kOgiEq2RZrpYeWpuee
dpWyF2qMClqh7Ui1GOcUJvpVQRIYWPK+wFsxlYagAAoflK7k4lQLLOIRMpa6ngAfZlnie
hKxaLPkL4iNPzC5ne10yIGi4C2Q87VV1zA+TLddCRqmDOm6Is/Ph3vzqvw9QZZhwYbQ==
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=s6tzW80O;
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 54C2A60A6F6E;
Fri, 30 Oct 2026 10:28:52 +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=s6tzW80O
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.42
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1793356131;
b=Zk2zubT7G/uPkKlIt70KkylQ8t8/oxy5wRAP1gl6MGPbVkB4LYiOq40xmjSwQ6qQ40Sn
KxHLzOVbyq8217WpH2SAMDutK3G1sSlVOexHOs/6E8ZvM/9vPRwh7vocy1CeupBawRmLn
Vu/uWLbCxRLPzEJH2LiA5qCITT22l11gCZfGdCMfKZfnmq7IlWPqxqje63e+ndV90uQUp
hoPGtQD3nqE2/8wkJ/kRo/G9qfb1zoOsp9VXApM4gyqUurCBTuVl3zW9FpPYiZ2amnPTK
urQwFIcxJyQaDJkBlRbY2a3osBDgHX/KH5DkZemvQzRszWXptOXfyNY8h2Wvh9UvKMg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793356131;
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=aeZlgdld8Mlenh+df9G4lQ3t/qfooZFG5zrAZBl7IVQ=;
b=ueQL1pLF0nznV/r7k5Rq9ZtEzJyo0HMphGfNaFdxpmDW5xjMh/QMGnIA9iKI2qBGkMiP
DAZrEB5zGEb8aLWy+pDJ2SDM6fDDXFTO/DPPyyB26HDR2obNcMBqHZpBj6ZCtPjpm0yuZ
ioQbBkuXIP8/Kx5dXru8WahnGyBroSRPbwk2t9tMsHENMShGPMHEIJbchNuySDKaPiLKI
xINkuhapVbgAXgYCpZV4S+g5meJ0TKY07/SsMKU5DklT5sBpCc6mcGx9GUMveNU7ByXSk
nvEulGUuN0/fA4XTcJ8IbOqM275Z9cGsE8BhEWRYXL7tShQ7aS99jPSSF3X9zG6SISA==
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=s6tzW80O;
arc=none smtp.remote-ip=209.85.221.42
X-Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42])
(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 21EB260A6F57
for <git@vger.kernel.org>; Fri, 30 Oct 2026 10:28:50 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 21EB260A6F57
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-f42.google.com with SMTP id ffacd0b85a97d-48dee593f18so460053f8f.3
for <git@vger.kernel.org>; Fri, 30 Oct 2026 03:28:50 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1793356129; x=1793960929; 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=aeZlgdld8Mlenh+df9G4lQ3t/qfooZFG5zrAZBl7IVQ=;
b=s6tzW80Ou7GTGujaCHoWbkTEbygRoLo4m3oJgQgieKWX+VhCLZRRTo6wMobilPc4h5
oYfwKi2+shbglykcK7aXkdGPNTqQuwhPPzUzhqmsDjJKsUrzB46QKotNgjkkgz0k4qWB
yhEbsGCMRU6+i/i1gDlXFIN4aY4SXf/Pj41wRm4KJNALNNO/ghtHNo4TjPRgG04ds1KE
00cgbNsPshpnPBcyZTUS6xIkzT7qmvOD4uChqdzIeteQbSkxwu9c5QZ48908/cQP3Jvn
J8rcoLTJYbKrHaCxaE9rgtQDbYt3RM/NAxDkQkrZpPIQbCoPBNny1VqJ9m1AOBoN0x5L
wGBQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1793356129; x=1793960929;
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=aeZlgdld8Mlenh+df9G4lQ3t/qfooZFG5zrAZBl7IVQ=;
b=om3z0CH31zSnGxwZ6NXSj3de0Cknx1zAwJsVpiwbRsMCoOJN26nNfsXsPHxmt37iE4
dxYw4gFVKpIRw4lMcXfjxJgmUYfRKkeur7GuAqHLEmfhWUPwwRr8RTg9LUW5HVO/Rvx4
50I6wbWYcKXgYrCdHeLvC62+s0714KF5cW+m1mHjMqyoxCy/UxHuHj8tIPtiaYHwrZok
TDy6DqX4pqY2henLRRr9t1fHIEAmxg++yTg7+MBt5S0BXVkwQEDksEqZVEPnEMkqpzNM
3GOsezWpAWgZgS1XbXUeUq/i/+JhzqzjnR1s96vUMl99iuLzVFhmMUZrn9+dArXI3i0R
fvPw==
X-Gm-Message-State: AFq9FYK7jYeChla05ZLrrYrEecS16XEoh8iyULSDVX5WRAsIWG2SUyUp
4aJRxn5KISO2AvOJizgUDlMq0K6h8RWmK/eLXrqGJ+rK/UJYpvRzGFh6/dLFBQ==
X-Gm-Gg: AYBFou26D2TqyywailP3WXh5GyZitlkDa1LvDeRQVGFKdHrKdT0a4TIkNaxamTZyQs9
jb7VdRnG9ksRnnTsLs0ZHdo/PoAVop7ZR4PXQd/wTJ7ee4pERZXCuJWHvrQRf4/Id5/owbTii/C
rO0suwAPX9rYoQsCTVmFZt+feL4Nw0LQrvLMWBXdcQeTqSTx+KMn92hOUCibAjw2iGOxeSJj7tw
NqmiTS3ucZvKBI7PEWrTD1VoNEWr48hLt7R4/Bx9i0cYQadgOQw3M98n+pjd5yWp5czY727c6r0
ZgvpDdQ2Qt/TGvzqg00X1pq9qzCShrptTpfXLqSIhAVDi+7R6iTZmgnpEonu+mTPainEBBx883+
tIHTLFcu0z0nm2e/GAr8jXFC/yOiBZUXiNXYLy4k0wYqox0CFKWvM0i2jS/txtJU0D0UozpncQw
w37SJsqEkp2wpo0zbcbm3865feXdX/mjegVAXsImgrheJUUxdClfXfPnLGCBnxNq++3AuBYqRZe
cQCpJy3oqICHvcOh0cH7WR8UR09/jxHLE8miFPT+x4734Y5TWGkVo7+oMCmyK5hcLx1rQQScI45
DXAH/2BHQWaFIRF4rSgxs0C6Ui0IUVVzncrGQgI6Px09cCz/gg==
X-Received: by 2002:a05:6000:4a0a:b0:48e:2448:ea23 with SMTP id ffacd0b85a97d-48e6e307864mr4787475f8f.55.1793356129352;
Fri, 30 Oct 2026 03:28:49 -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.48
(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>,
Junio C Hamano <gitster@pobox.com>,
RenΓ© Scharfe <l.s.r@web.de>
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