Article View: linux.kernel.git
Article #1222Re: [PATCH] [Outreachy PATCH] diff-delta: use safe integer arithmetic
From: Junio C Hamano
Date: Fri, 23 Oct 2026 05:04
Date: Fri, 23 Oct 2026 05:04
64 lines
14914 bytes
14914 bytes
"Srujith A Poojary via GitGitGadget" <gitgitgadget@gmail.com>
writes:
> From: Srujith A Poojary <poojarysrujith@gmail.com>
>
> Replace manual multiplication and addition in create_delta_index()
> with safe integer helpers (st_mult, st_add, st_add3) to prevent
> overflows while preserving NULL returns on failure.
I do not quite understand what the last part of this explanation
wants to say, i.e., "while preserving NULL returns on failure". It
makes it sound as if the function would return NULL if the integer
helpers detect integer overflow, but I do not think that is what
actually the updated code does at all. st_add() and friends will
simply die() when overflow happens, so you will not even reach
malloc(), let alone return NULL when the malloc fails.
And if you reply to this review message, please do not top-post.
Thanks.
>
> Signed-off-by: Srujith A Poojary <poojarysrujith@gmail.com>
> ---
> [Outreachy PATCH] diff-delta: use safe integer arithmetic
>
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2276%2Fpoojarysrujith%2Fc-refactor-target-name-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2276/poojarysrujith/c-refactor-target-name-v1
> Pull-Request: https://github.com/gitgitgadget/git/pull/2276
>
> diff-delta.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/diff-delta.c b/diff-delta.c
> index 7cbedeb507..45df070ab9 100644
> --- a/diff-delta.c
> +++ b/diff-delta.c
> @@ -162,8 +162,8 @@ struct delta_index * create_delta_index(const void *buf, size_t bufsize)
> hmask = hsize - 1;
>
> /* allocate lookup index */
> - memsize = sizeof(*hash) * hsize +
> - sizeof(*entry) * entries;
> + memsize = st_add(st_mult(sizeof(*hash), hsize),
> + st_mult(sizeof(*entry), entries));
> mem = malloc(memsize);
> if (!mem)
> return NULL;
> @@ -258,9 +258,9 @@ struct delta_index * create_delta_index(const void *buf, size_t bufsize)
> * Now create the packed index in array form
> * rather than linked lists.
> */
> - memsize = sizeof(*index)
> - + sizeof(*packed_hash) * (hsize+1)
> - + sizeof(*packed_entry) * entries;
> + memsize = st_add3(sizeof(*index),
> + st_mult(sizeof(*packed_hash), hsize + 1),
> + st_mult(sizeof(*packed_entry), entries));
> mem = malloc(memsize);
> if (!mem) {
> free(hash);
>
> base-commit: 47fdf2208c5b94c8cc01c106b8f7c85efb91c926
Technical Details
Message-ID:
<xmqqld7paty9.fsf@gitster.g>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-72933-linux-kernel-git=dewy.ruReferences:
<pull.2276.git.1792727808109.gitgitgadget@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-72933-linux-kernel-git=dewy.ru
From: gitster@pobox.com (Junio C Hamano)
Newsgroups: linux.kernel.git
Subject: Re: [PATCH] [Outreachy PATCH] diff-delta: use safe integer arithmetic
Date: Thu, 22 Oct 2026 22:04:30 -0700
Organization: Usenet Network
Message-ID: <xmqqld7paty9.fsf@gitster.g>
References: <pull.2276.git.1792727808109.gitgitgadget@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: usenet.network;
logging-data="414672"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:X9TPctC4il2q/f9J5jy8GQLlvBU= sha256:BXi8p0AAx2Fp4PZUix4eEcurEqCeunr+WO2ciSswy9Q=
sha1:e3HbTUOkz8H2PEcX+uCa5IMERBo= sha256:zgnl/naFf5G+Ig3+8HxbrXxEgwCIm5x0zOT6PI0G8G4=
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 9EC1F1113EC; Fri, 23 Oct 2026 08:04:59 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.15
X-Spam-Status: No, score=-3.15 tagged_above=-9999 required=6.31
tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
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=pobox.com header.b=HXXPOJ4C; dkim=pass (2048-bit key)
header.d=messagingengine.com header.b=axdwwHvj
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 SPR5wvauSMip;
Fri, 23 Oct 2026 08:04:55 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=git+bounces-72933-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=pobox.com
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
by mail.dewy.ru (Postfix) with ESMTPS id B2394110E3A; Fri, 23 Oct 2026 08:04:41 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sto.lore.kernel.org (Postfix) with ESMTP id 90B2860B1AF; Fri, 23 Oct 2026 05:04:38 +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=1792731874;
b=awk3QzcGp82I3EmETQcNGchvsuDtwR0tBGsKmpTDUXRor8j85ARxYX4xYECK7NSt68i1
zzOSCI66W9tbZGL7ky8Tk8KEhyIf6S6hVD2uWbt3KRQt8hnfx9F+O+tOvQDGF6OiQzoan
c2GJzYfLIUKh3+TjAn2ggu+n9mQ3w8ETYf1lwVk9SeDGA21LaHmHODpR838kRXt2ynXV1
gtX/cYh2SBgczgjLUh7ZfS8HGgIU/QohSCwkXq+py0iuwq0958lcuHeQa9daSMhOu9xWG
vGFKKT0/P62nXCgJUYSUkBhr1XB1XOhRvTfRvTxjRIr3sZVsxoYsed70+YMor6UG0Nw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1792731874;
h=X-Original-To:Received:DMARC-Filter:Received:Received:DKIM-Signature:
DKIM-Signature:X-DKIM2-Info:DKIM2-Signature:X-DKIM2-Info:
Message-Instance:X-ME-Sender:X-ME-Received:X-ME-Proxy-Cause:
X-ME-Proxy:Feedback-ID:Received:From:To:Cc:Subject:In-Reply-To:
References:Date:Message-ID:User-Agent:X-Mailing-List:List-Id:
List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
Precedence:MIME-Version:Content-Type;
bh=V7ezuakHVRPhYwZWs4eXOKIGY0XlSNM9iSb/WifZsDc=;
b=miRkz+qMU0w8ZlIu9sxkyjYFORiNAN26dAR1gOxrtWc1NaYmsb7CMJcdmXrEiAb3QroI
MowB9jqdkwc0YkHOyf95wdECXXGhWVBuW8Qe37NeataePTynpLIeRIrDIHdZxy8MUw6gV
nEboqgI63FVspIpaQlu99B2aYyyDIGx9s4blO5W7tGPmqA0IU57j3h6oBJ2L1ELpyjIIE
dCz/H2Grv9imo684sl6MUWwKWZ4SHrLvVpsZc3//qaS/urRqnn/Vz/9t7ynQqNpvsYyQy
vYQU4wtLtAISGpn8bqRMB/+KnlaSaQ160REPO79EVO8dyLwj7q4cnlYzuGO3A+1WyPQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=pobox.com header.i=@pobox.com header.a=rsa-sha256 header.s=fm1 header.b=HXXPOJ4C;
dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm2 header.b=axdwwHvj;
dmarc=pass header.from=pobox.com;
spf=pass smtp.mailfrom=pobox.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 394F9606A32F;
Fri, 23 Oct 2026 05:04:34 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key, unprotected) header.d=pobox.com header.i=@pobox.com header.a=rsa-sha256 header.s=fm1 header.b=HXXPOJ4C;
dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm2 header.b=axdwwHvj
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=103.168.172.156
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1792731873;
b=XqavXTGoG6IQwOa+01rtJC2AmcPcZ79fmrU5J7TcPGhXzfcy3Z2XSADRWYbbS/mg/lfw
lQ3JJhcGqya10ALOsgNRw9+dhTVqS+Pyu85pjVJyyr5xLqrXyWa+Vb6+gYgVIqZ+S8jLC
l996E1FP+S57bsfKjL6F/EaY/S2ZXJcBUDpCroXgAW9IEMhYmBBIreuMlYu/F4GFvpKwq
I87U/4dDQqFtNrgPnwGPv1qhhJBaLnYMQ9bd2Xf2UQc/TP9S+cT1LRW+HrWR3lPcd8ZCL
ANtyMTIdJwfHB66gSYWSSBEv/3+SIYhdD+wwhYfMGldZ8jPYyZUpGiIkyFCe+6B8k5Q==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1792731873;
h=DMARC-Filter:Received:Received:DKIM-Signature:DKIM-Signature:
X-DKIM2-Info:DKIM2-Signature:X-DKIM2-Info:Message-Instance:
X-ME-Sender:X-ME-Received:X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID:
Received:From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID:
User-Agent:MIME-Version:Content-Type;
bh=V7ezuakHVRPhYwZWs4eXOKIGY0XlSNM9iSb/WifZsDc=;
b=Duu+QXjJLRA5BRun/dEKvHGsd7NmwFSACLMZ7mIpXr+5piuz2yDr83B/f56AcNPeVg+E
QQWmzNpMfGZZEYuhXdruuJWnnKgD0Wn81T0Im1IXszKdLlyPGjJJ3JN/K6nb0oHzdMgVs
lhkY2GbFqhA9s7zd/1uyS7N/H9/r4q6fv1gX4t3YHyCBdqb9F9HLiovwISvJMQBhdSsbI
wr38FrtzpmbqbUZMYxRJiiUTOS0C5mJ4GcE8kz8zLEYN3XoofM7xEQjM+ucusFUNxjiGF
yELbnbes1tBS83TAO0PQDRQJhhyv4Nhcu1S3YZ47cscF3UzYZNSmd/iClSZX6f6JhFQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=pobox.com;
spf=pass smtp.mailfrom=pobox.com;
dkim=pass header.d=pobox.com header.i=@pobox.com header.a=rsa-sha256 header.s=fm1 header.b=HXXPOJ4C;
dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm2 header.b=axdwwHvj;
arc=none smtp.remote-ip=103.168.172.156
X-Received: from fhigh-a5-smtp.messagingengine.com (fhigh-a5-smtp.messagingengine.com [103.168.172.156])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature ECDSA (prime256v1))
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id E3FDA606A31D
for <git@vger.kernel.org>; Fri, 23 Oct 2026 05:04:32 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E3FDA606A31D
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com
X-Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43])
by mailfhigh.phl.internal (Postfix) with ESMTP id DA82E14000CC
for <git@vger.kernel.org>; Fri, 23 Oct 2026 01:04:31 -0400 (EDT)
X-Received: from phl-frontend-02 ([10.202.2.161])
by phl-compute-03.internal (MEProxy); Fri, 23 Oct 2026 01:04:31 -0400
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pobox.com; h=cc
:cc:content-type:content-type:date:date:from:from:in-reply-to
:in-reply-to:message-id:mime-version:references:reply-to:subject
:subject:to:to; s=fm1; t=1792731871; x=1792818271; bh=V7ezuakHVR
PhYwZWs4eXOKIGY0XlSNM9iSb/WifZsDc=; b=HXXPOJ4C7kr4X18HXSfbhIee/p
E/HyR9TsSFt/dQ+8zW/7uhzrP0w/srH2FGlkHCs6yrS+5Z5KjoPX9+1PQLy99rjx
R6Hx+a56O3yo1mHQeAx+gW45ev7n+wko2pmhi7FMr8nDu0QVuUG6HFfOIr+MRGrz
9rD/NvxLHjlB8dskYNesYmqF0y+i9SY/LVo73bO9wdG/U2aMHpGaR11acpBQRzcy
FA2dbbO0XdgqVKtVbg15YKpsucZ4VPeKoTYsYeNKoUCyWm6/DB1m4BXANhQCpGf2
XoU+fJnaPtTRAp2i0FdMplBaa2/I/gTajKnuXuE7sZg5OQkEHFahIY4liyaQ==
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
messagingengine.com; h=cc:cc:content-type:content-type:date:date
:feedback-id:feedback-id:from:from:in-reply-to:in-reply-to
:message-id:mime-version:references:reply-to:subject:subject:to
:to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=
1792731871; x=1792818271; bh=V7ezuakHVRPhYwZWs4eXOKIGY0XlSNM9iSb
/WifZsDc=; b=axdwwHvjAfrkFS7QTEuVa4CegZDNS5Q3DigxVy6H1siNu0umpWL
5+wL5gm07ZioY7G4MSAkD6pSALMXJ2jWls2G+M70HOt7xPmZq6+Cl1hjJyzU95JT
iqJIopCAdjjOI08hdb3fnHfQ9nWmfJyQSyPUHzZnEpOm0Dz1UjNEoFLSE5i/rrfU
wUNJPwoO+iHizLINEEh0QVwj9vVLa5jC6t5irwfS0PgEfJU0lX3nJp2ZTbRcYqBI
/CSu7jRjzBjyUNWtT1AOzSXNBC4tH0adkCNEEFr6elumN3jGJl6rEulTq88S99hC
DtLAIEbKsmNwKaEBqeIuPvtREAO8Oehsdtw==
X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-07;
repo=github.com/dkim2wg/interop; date=2026-10-18; sw=lmtpprox;
action=sign d=pobox.com a=rsa-sha256;
X-DKIM2-Signature: i=1; m=1; t=1792731871; d=pobox.com;
mf=PGdpdHN0ZXJAcG9ib3guY29tPg==;
rt=PGdpdEB2Z2VyLmtlcm5lbC5vcmc+;
s=fm1:rsa-sha256:QCGFzCZMoKeLSjoh45Yjkmf9wBD+AS1c9XhpdJ5kwLnHwbh
LNYd11RzI5BYgw2EXikZq6kANcLoIOjA9DXNE6iVsoHhX2YYu3YHt50+U/xYhz/G
wgb5oNuLDQPTbrD8Be6g60878R46NK6pMi5PK0Sbv5wVafXXPg+SyNetDFXK6qFl
tmaNJZG2jDREAAk0qc758oQ12lciBj21pmjaEciXu0utjkdZRDo+OmEvhc5Jp7KN
w0x5p6H0wiUNR+np4mLUJ/rH7401M4kREqjBrAmC40Dr9eQ/DEaSPfsYm4qQOqez
vEFsaY2fuXcUizbHVBeHUB+QKDw/pzfuB7BDLUQ==;
X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-07;
repo=github.com/dkim2wg/interop; date=2026-10-18; sw=lmtpprox;
action=mi-m=1; hc=12;
hn=cc,content-type,date,feedback-id,from,in-reply-to,message-id,
mime-version,references,subject,to,user-agent;
X-Message-Instance: m=1; h=sha256:8r7F/fhHnVlv59rEvZa9TWkr2Uco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skQEiNMLAc9Q
X-ME-Proxy: <xmx:3-raasOu54pJb5z8XlnY_b4C7YAF0OXsFq34nEJXMZAITaMNzC0thw>
<xmx:3-raauboAtDdcIJ7hxMDSFG5r1raO9Asjql2Ox-XpHiF7_25l4iXuA>
<xmx:3-raamzhbt79N3gB7ObSAI9j_-uLmzaB8mRj-Ihch5TJBxswd_MxPA>
<xmx:3-raapLpeeZoEjVeWmu4_u3xsfY_XZ15hSM5sH0CDq9yBVYEuSxWzw>
<xmx:3-raal65z4uaWjxvl0rBG4YMauHE4Vqt51qyCmOHmgwvcSwwPkjn_jom>
X-Feedback-ID: if26b431b:Fastmail
X-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri,
23 Oct 2026 01:04:31 -0400 (EDT)
X-Cc: git@vger.kernel.org, Srujith A Poojary <poojarysrujith@gmail.com>
X-In-Reply-To: <pull.2276.git.1792727808109.gitgitgadget@gmail.com> (Srujith
A. Poojary via GitGitGadget's message of "Fri, 23 Oct 2026 03:56:48
+0000")
X-User-Agent: Gnus/5.13 (Gnus v5.13)
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