🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.git
Article #3314

Re: [PATCH v2 1/5] object-file: check size of inflated loose object against its header

#3314
From: Junio C Hamano
Date: Wed, 18 Nov 2026 18:17
32 lines
14291 bytes
Patrick Steinhardt <ps@pks.im> writes:

> On Tue, Nov 17, 2026 at 12:38:54PM +0100, Elia Pinto wrote:
>> unpack_loose_rest() allocates a buffer of the size given in the object
>> header and inflates the rest of the stream into it, but it never checks
>> that the stream actually produced that many bytes. If the compressed
>> data ends early we return success with the tail of the buffer never
>> written, and callers like odb_read_object() hand it out as object
>> content. For example, "git cat-file commit" on a loose object whose
>> header says "commit 200" but which contains only 44 bytes prints 156
>> bytes of uninitialized heap memory.
>
> That's certainly fishy.
>
>> The opposite case slips through, too: when the whole object fits into
>> the buffer filled by unpack_loose_header(), we copy only "size" bytes
>> out of it, the stream has already ended, and the extra data is silently
>> dropped.
>
> Hum, this part I don't quite understand. Do you mean to say that the
> header declares "commit 200", but it actually carries 400 bytes, so we
> only copy the first 200 and ignore the remainder? If so, why would the
> stream have already ended in that case?

The opposite case is that the initial inflation into 32-byte buffer
is sufficient to unpack both the header and the payload.  See my
walkthru in https://lore.kernel.org/git/xmqqbj7ndzi7.fsf@gitster.g/
and other points you mention in this message would hopefully become
clearer.

Thanks.
Technical Details
Message-ID: <xmqqbj7m6m25.fsf@gitster.g>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!git+bounces-75719-linux-kernel-git=dewy.ru
References: <cover.1793355390.git.gitter.spiros@gmail.com> <cover.1794914210.git.gitter.spiros@gmail.com> <edb5f34498e91beb0480d9b6ac417602580b3016.1794914210.git.gitter.spiros@gmail.com> <av2YSgkd2fUNRlNM@pks.im>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!git+bounces-75719-linux-kernel-git=dewy.ru
From: gitster@pobox.com (Junio C Hamano)
Newsgroups: linux.kernel.git
Subject: Re: [PATCH v2 1/5] object-file: check size of inflated loose object
 against its header
Date: Wed, 18 Nov 2026 10:17:54 -0800
Organization: Usenet Network
Message-ID: <xmqqbj7m6m25.fsf@gitster.g>
References: <cover.1793355390.git.gitter.spiros@gmail.com>
	<cover.1794914210.git.gitter.spiros@gmail.com>
	<edb5f34498e91beb0480d9b6ac417602580b3016.1794914210.git.gitter.spiros@gmail.com>
	<av2YSgkd2fUNRlNM@pks.im>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: usenet.network;
	logging-data="2661754"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:HDE3f0vVS+EcClLEcsvQROQYeGA= sha256:F/HrNXfUmIj4iRVxXB0+7LKanlWsY8PjRTW5px7Ul34=
	sha1:axitdOogAC30Gqp18N7pm2V6SAQ= sha256:AIslNIq6PspiJV9xYd4BRR4kqNFufjEV6CWEWyOQihk=
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 652E211535B; Wed, 18 Nov 2026 21:18:47 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.05
X-Spam-Status: No, score=-3.05 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, 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=pobox.com header.b=GC+3KhKl; dkim=pass (2048-bit key)
	header.d=messagingengine.com header.b=UrbDVnPm
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 Z78rkKFMGUmT;
	Wed, 18 Nov 2026 21:18:42 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-75719-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 5D975115359; Wed, 18 Nov 2026 21:18:29 +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 60BE0C2315; Wed, 18 Nov 2026 18:18:00 +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=1795025879;
	b=5DHfKB5jGyTr/Ahou9cdLXxB+8snJEa5Rvq1QqZGvhGDZzhMRhdCPpLYy7ukyr9wGZc8
	 FNM3ylWhid4h9KdGjDr3gViw8e/nVDYu96W3KfkGhvJG3l7eBksSIobUtapCSmfQGHsEN
	 +bW9hxpSNvqhv7q1R3bxXl55Nrc1Vpojt3/YcXppFpp0bJ3z5/cBFucCYOHOb7RqBfhtr
	 +t7XKu9RSusJ1AXPzeOVTiGjeZZb+bDMPDBGk/X67B2ZxmH4y8UYZVCy3Lo96p/kG9Ebk
	 7QqNu0LC70n/v9tPKHMErOMKxhRT74F9sHzZv1fAcosZWwoMU2QfixRU0YOv9AuHH+A==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795025879;
	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=UbMxOHP2aEkdloT90hQS4x2b3jNvJ4mJJ47ksT1or/E=;
	b=YOlnFaKGpeZxDsil3pZUzVRiDfoSrajPiiwRwbRjlVTsmGeYImLrf8guwVWKo2SomogG
	 OiAx1cO9xaXhJbj2vQk05lCBWYKvBjEzNy8PtbJ6WmGvgT205QnCpuvC4cEckRh75R8Hb
	 Z4Ohnec5SyrB/2KJd/M9A9N+3+Y2k/Tn+VCWhqiAuLeDCHLhCxeB3Vu7saQLmaq9xkUrQ
	 +FKQa3U53l+BXaq9/0SQpEOmrhJWyU4MFMH1zxROrUQj0APBHXr+zS+mYE3MgVn3XURo2
	 82xHwR0jG0yA4BPWNsgzDhW/v52Jp7j8g3ELwkpq1VQgWyodw+jiMiRuA/hodTEgKnA==
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=fm2 header.b=GC+3KhKl;
	dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=UrbDVnPm;
	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 CBDA6606A32C;
	Wed, 18 Nov 2026 18:17:59 +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=fm2 header.b=GC+3KhKl;
	dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=UrbDVnPm
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=103.168.172.148
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795025879;
	b=ueuJ0+dhyJGb4pqfnnBZs69W4IKjCQahsWmZAJBD1Lp5pjJ8o9UKbSTCtVevwh6privv
	 mB43klnK0wdZxjkjy6tlSPDhNEDc/tpUiYMBKjNXOpWgQVutKfMqXvRssBMZq/nPkfL+i
	 mu30szXSgt/LPhEmVusF39Tfzvgt670+ePoVOHGPxBR6skcFz79e3jvE9o7Fzc9nHo+Tw
	 k7zvxbNL2KazgbPMSu0GHrtlm2+/dC5bkwUMZS0oU7Av5+KBMb5J3xPuv8fwT1XYuQ0V5
	 yyTmEC/Zr7qx5K10NbrXWoVliUEVCCBjto39jeXjQM/wlv8krS1POPZotVMfruv2WfQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795025879;
	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=UbMxOHP2aEkdloT90hQS4x2b3jNvJ4mJJ47ksT1or/E=;
	b=OQASHBfiGljV1mttUkCe4KaypDt0KaT3w5WszJFmi75qB8N3RwuIUWfZwCZGd5WByEEc
	 uwdGF5QMVVuJnjC7qpXsi9+vguwrBXQ03bi4rUr2gLRvRqw0L4HiaA6wxrPshv55iJbul
	 J/gkDRJP8Ie4BwJXpcengoRA0iI1gee3jgFaayRgVN3n21lBaMe4wB8ON2IP3/CLPnJLO
	 FKuRNYtrlnY40GvLu+UBgDiAUx2fSv6CxWisexcQ3LFvd2DO7SEighVjafxkkjDXQwtnt
	 LqruwUqoU+meyUXKZP4Truv4S/nVMbnO2r6r7ywTpDz9ytjmqDFpWLwh4wuqGPdI6aQ==
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=fm2 header.b=GC+3KhKl;
	dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=UrbDVnPm;
	arc=none smtp.remote-ip=103.168.172.148
X-Received: from fout-a5-smtp.messagingengine.com (fout-a5-smtp.messagingengine.com [103.168.172.148])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 50EF2606A32A
	for <git@vger.kernel.org>; Wed, 18 Nov 2026 18:17:58 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 50EF2606A32A
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-01.internal (phl-compute-01.internal [10.202.2.41])
	by mailfout.phl.internal (Postfix) with ESMTP id 7E6D0EC05BC
	for <git@vger.kernel.org>; Wed, 18 Nov 2026 13:17:57 -0500 (EST)
X-Received: from phl-frontend-02 ([10.202.2.161])
  by phl-compute-01.internal (MEProxy); Wed, 18 Nov 2026 13:17:57 -0500
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=fm2; t=1795025877; x=1795112277; bh=UbMxOHP2aE
	kdloT90hQS4x2b3jNvJ4mJJ47ksT1or/E=; b=GC+3KhKl1xuLomKbzLBESa04us
	0DMUNLQnZd+rQRHd0Mvd3h0UQTRorG3248MlWVLkp6EzUBDBwHiRoMo/BPW4KDX9
	zFuccj/rsZGIxVIjYxGc4SvgiiKGf4COMJgpb/zMqVKGLt99Z8tENjzohcnT7Plj
	P6KWRUIlejSfc78TYyq9SMH6G/9ZoT07fbGuW68CsjfTTFnBVVoVAfwoc7d2Uo28
	ilFzBZ0NVXEUhObSvxGJiJj9iQs/xXdvjnwq4lgoJ9vK7fbZcZZWeGLoiRiYl4yA
	3KhQeA4fUXydLjJUVdVEZsi6d9EAz1af75CbsPQV7GGxkq6ejf1MOOiALRiQ==
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=fm3; t=
	1795025877; x=1795112277; bh=UbMxOHP2aEkdloT90hQS4x2b3jNvJ4mJJ47
	ksT1or/E=; b=UrbDVnPmGzDCVOoDpi1zrBJoKK3knEr9mYszmpJXmXOrpSillrl
	FuP5/5qeiiBpEKg9mYvz2MVdwz3PYGl4rTJh/F8KJCZflmIKZG7Yu/AOJEhBE7Q1
	scOgssB953Mk12X/ZBArjBZ4R5sIGCvUSvWmLu9uQA1BXArRwquaCzSbUSpvQCX+
	eEAX9X6RswEWYy2/1DV2hcSktGuEp50YF9GHU4WRKJ4zVCgT7h0T/ANGrvLeNDqi
	EnUemevqW0o4gM3nmegtdXkaobZmINVDJ/yP7CeEjKlQ7Qj5R9eXKc61+RamDvDZ
	60woSVcdOAEMeBTlesHbqYVzv4a4i5EBkzA==
X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09;
	repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox;
	action=sign d=pobox.com a=rsa-sha256;
X-DKIM2-Signature: i=1; m=1; t=1795025877; d=pobox.com;
	mf=PGdpdHN0ZXJAcG9ib3guY29tPg==;
	rt=PGdpdEB2Z2VyLmtlcm5lbC5vcmc+;
	s=fm2:rsa-sha256:TjTGGosUWFLKBsUVf+MS1cVYT6dKdXcdQ8lWUrtGQ/cAkrz
	NF0VDcjeTNs8GDFjhmXYtLcRS/uh9MzCMQTkEkAmY/k4S/CFTqLycbGpk6w/2csj
	pO/iK+si8VT6CVJAtEDE567uX5H3gXmoRTI3tH8wN9OUkyeTMvfCR2/QHbrhOZye
	eKAe0Xet3BjwNog+896vFEKE7sMOraOEy685rrQ0oQ6aXQ1hxwSW/nlSsaMdOnN9
	dTvCMnpClf8b8wrdxIZ+MGw0L4Gb2KvbJKbOPyh+uZ1aTBxoFcTIRZDqka7xVppv
	wXexG74ZyppLDDQnmFm9pxqBph0xr0jDuOB/CNA==;
X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09;
	repo=github.com/dkim2wg/interop; date=2026-11-03; 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:n7RjdJ/QSOKp3SKg2/OfiJ0/M7UDJ2M1Kn8/H032ruk=:t7BsCIoN6F2VFR2lHLvMteC+HtTUq5dwqRuQE/lumWo=;
X-ME-Sender: <xms:1ev9ahGHNMIXyrK4s4Z9-CysjsWe9Vmqah35WL8KDtpMk0IGz-O9gg>
    <xme:1ev9aonMMCINzoIff9iVmWt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ev9aoN6whvAPK-XKulNtCYcNaUy59p3GmEl5xbdHbAv24wMd8Zl7A>
    <xmx:1ev9amk3foquNyVee1YzJVc7AO7BSXZ-yUnSxBXwDHeoDE2xttpe0w>
    <xmx:1ev9av2SyZa4_5wYPFfWvpCBWGSyfVeLjneAcq0pjccJY6YUCB3uqzTk>
X-Feedback-ID: if26b431b:Fastmail
X-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed,
 18 Nov 2026 13:17:55 -0500 (EST)
X-Cc: Elia Pinto <gitter.spiros@gmail.com>,  git@vger.kernel.org,  Johannes
 Schindelin <Johannes.Schindelin@gmx.de>,  Ævar Arnfjörð Bjarmason
 <avarab@gmail.com>,  Jeff King <peff@peff.net>
X-In-Reply-To: <av2YSgkd2fUNRlNM@pks.im> (Patrick Steinhardt's message of "Wed,
	18 Nov 2026 13:21:30 +0100")
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