From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=103.168.172.151 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796399236; b=mYSM/cuGW9SZ0n+HjmmdC+1wa0CQ9YU+mJkfl+nyd//QHJSwJ4P0nCpPJxVZIGRPc1rd slq8CsfHylTkAuDf0CVvDXFMpqvIQGwzEpw2rBwTr7SZRAQbG/MaMBrwX468MlPaNwcED AoeRtMgvFxaPqpJj9KP97COUmSx8pvqMwJzVBMLwZcvvh+4n+mRP7aGfANefxIPNQJGeu Z1YEmqxWSuvxRTPV/WkmFVXXLrZT/Fi4cc958XasqSwahigMR/m6SRortdNn/dIQ5H762 Babdo7xqfrIjRI6kcZm7iULqmrQ41RC7N8JJSyvuqOEOy67qKob/2V6LGkvOPAGLRTw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796399236; 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:Received:Date:From:To:Cc:Subject:Message-ID:References: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=lS35Gga1Cs9zUAcBcuQLRA8nxjXnRn6LTVn96X6hJnI=; b=CnacKxfZSUvCmI4td6pPr3RN+20tjYRvPVEgVy54DBCh2tpfKHZKtO6fLhKk4H77S1wc 9LcwJzN02NHK2hhUAG2MlA9RvL42xULtfWekEwm+1+NSKUct6bYUEO+TpxgJlPi51fS9v CrMBI4YDWju2rOOqgTtIiOkg3I+m0eQU5wO2nU6315xmRTAx/i4csHBLdfvGQZzXhmZ3L 1qvCCTRqPwSzmoZ2ZiwVBqTFVqIhfjZpTJm0SDNNks3pixe80owDF8v6ZxMox+qhcU8zY i/Tg9bwcFrpl8dI7P/5EsLRQHfe1L3CtZQ8K+fB+/TUDGMajGeGOlwW8eUV6f4MbljQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass header.d=pks.im header.i=@pks.im header.a=rsa-sha256 header.s=fm1 header.b=RK+hVZgO; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm1 header.b=kDmLh3Cu; arc=none smtp.remote-ip=103.168.172.151 Received: from fout-a8-smtp.messagingengine.com (fout-a8-smtp.messagingengine.com [103.168.172.151]) (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 74B8D606A322 for ; Fri, 4 Dec 2026 15:47:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 74B8D606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=pks.im header.i=@pks.im header.a=rsa-sha256 header.s=fm1 header.b=RK+hVZgO; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm1 header.b=kDmLh3Cu Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfout.phl.internal (Postfix) with ESMTP id A71FAEC0460 for ; Fri, 4 Dec 2026 10:47:14 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Fri, 04 Dec 2026 10:47:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; 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=1796399234; x=1796485634; bh=lS35Gga1Cs 9zUAcBcuQLRA8nxjXnRn6LTVn96X6hJnI=; b=RK+hVZgOhg49eqyjyDjinkZfVv o3CubZJYwlWy0PjV6NY/IUke+D3DrbhpukiSuIw+BZ1pBvCZJNAxy9CnuzrlT0OM ssaxGd853lJNVBHesTmTydIXjaCoVOjHyStHocQu5E7/BYtSsPi2sb3DdfdTW/C6 Lew9Pqzx2LE4R2qNkxuZACGOLOmVmLKECi8WB5utepWC8XlyJhU85ulML4WmgbRT u9J/CMMjLso3xoljjcUZOQzkuo+TpciobjqRtmu24X0UIBK1aeBHJ6pNKfpyCfNv Hib3aMCAYaH5tV8u9YPuukT5FMxmHrGc9z/8EI6g2gbNGb2NioG2VGOn27AA== 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=fm1; t= 1796399234; x=1796485634; bh=lS35Gga1Cs9zUAcBcuQLRA8nxjXnRn6LTVn 96X6hJnI=; b=kDmLh3CunpYC+RowPbh0LdIG3aCvf+AREN0fx/aNFNtJvT25/wv lG9Xm4BUq8724I5v6AmRYkKuDiItGGE9fGCSOH1fjTJCGqld8sqrLB7Fqf3nM2fA auFgWx6nG5hE4apM2UpeZ11b0whULbsqN4sjXacr3l24GrHTWZioyjjUKz5iU05s 6WhE3nhO7KHAL7bV/lECV45XfELG1Ox1Sajb5U+pbDQOLk/kh/UJraqNIp7n0XLx EMdb8zK0RNUkCOUmk2JQbGhEooLFAPGVZNU5XR5fDDSOP+5rNqX5dCEd6IcdRHti y4zhZgeDqnXFs/hjSs9DLirJaJeEQDxoDsQ== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=sign d=pks.im a=rsa-sha256; DKIM2-Signature: i=1; m=1; t=1796399234; d=pks.im; mf=PHBzQHBrcy5pbT4=; rt=PGdpdEB2Z2VyLmtlcm5lbC5vcmc+; s=fm1:rsa-sha256:ANcwiTf4YRTm1lZ/nj5T/noxVmFVmguJzQGRIICX6fZwURb HZv1EV3b6I2h0/oPNdua4XDC/iNQ3mr/N9v/PoVW/YPDN7ysHil0oT2/B16KnTF+ +CoN8FY8LSPynD/DXZjVRtl/9/9xM2p3TSkVJIsVEIUAcAraSk9z9BFdEshJ4wLR /cGzqYZseaY/1nMgBbqEA05LPWp6aN80LBWIpn6IsLIiJsutGNz19dhmPCDoJQUl RySV//OuxcOUdwxAbExjT7qaAqkprG4ex8C3ZpjZbUy+zQeVgETGVxTpnpEQBvjy tFGXawPo+r4+b+Sh5U5ZnQKpRrya82NkX5ovZiQ==; 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-disposition,content-type,date,feedback-id,from, in-reply-to,message-id,mime-version,references,subject,to; Message-Instance: m=1; h=sha256:6AUR+YJFlp7qoN++Dvkzo1Mp1IBcYMrN6Knr9R/sOjQ=:P7050Tt5CEYQ6C9o2/tZfd/e38KeFSoLwqz4ROc1jQQ=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTE2CksDmoRZgaLvOYqeiL2yXDakirArXvoPlD061gq5H07h0TGDhwnzSsYkZyB/Hu Lrpt4v7X2c3rpFsfCGCUlGOPWjcn+n2knc+NVLdIS7N46OPZkcWJzO+FS1f4a9EoG5+65V hMwzIPr+GAe+R1wke2F9GgigIDxSjrnCAS7jhc1n6sph3tT7Uff3+RiTw0Xh6iO6bQJKvt 89BiRv8ASsmRcPl0ulkuu2honmlJQ7VaKJmdQ+MDd7FJkhxlxGJ44y9pQy7odWx/tgKY5+ PKUVQFp2WGMKjJV1iXV498BlYg2WEHrTowFnFA92hyIgsfgnq3qtIvj5Plyq0M+7mUiLq6 4DyM1MjkxsdtbujSWA/KqArsGWNykDihGvvqA3ylCeRWKSNLO2W3IukRbh5EQBB8GSOtMt UB+7rWtDICdXPyXup7OP0PVOwrOc6ls7tNi9YzIl1IAFYLqFrGmYMEcsO1pnvrJ9/4FUhd O0dLNkH4xtWi0+TrS57gco8Q3YW4bPvvbEnddmVYvbUoNgLc5owBK8FQLcSMo9F4Jf0/vW DiIFyiALIaAtiIDmOds3BdMUHw8hzJ5U5e5FMn6e6k25Z2hzcFXimXV14qrZKJOT47d/c+ 0WGw/uQAFFHEoomE9igD67j33D856D8vrloSxFk9GQTap/Pw5RQyvPe7CeXQ X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 4 Dec 2026 10:47:13 -0500 (EST) Received: by mail (OpenSMTPD) with ESMTPSA id 401cca69 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 4 Dec 2026 15:47:12 +0000 (UTC) Date: Fri, 4 Dec 2026 16:47:09 +0100 From: Patrick Steinhardt To: Junio C Hamano Cc: git@vger.kernel.org Subject: Re: [PATCH 2/6] t4201: demonstrate shortlog reusing stale buffer on EOF Message-ID: References: <20261122140347.41990-1-gitster@pobox.com> <20261122140347.41990-3-gitster@pobox.com> X-Mailing-List: git@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261122140347.41990-3-gitster@pobox.com> On Sun, Nov 22, 2026 at 06:03:43AM -0800, Junio C Hamano wrote: > When builtin/shortlog.c:read_from_stdin() reads from the standard input, > it skips the header lines until it finds the header (either "author" or > "committer") we are interested in, parses what is on the line, skips all > the remaining header lines, and then skips the blank lines that follow, > to find the commit subject line. > > But this assumes that strbuf_getline_lf() clears the buffer when > returning EOF. If the input ends on an incomplete line, that is not > true. Stale contents in 'oneline' cause the command to produce wrong > output. > > Here are step-by-step walkthroughs for the two failure modes in this > code path. > > * If an incomplete "Author:" line at EOF follows an earlier commit, the > earlier commit leaves its subject in 'oneline'. The outer loop reads > the next "Author:" line into 'ident', sets feof(stdin) while scanning > for LF, and returns 0. We successfully read the author of this > second commit, and then the two inner loops to skip other headers and > blank lines call strbuf_getline_lf() on 'oneline', which sees > feof(stdin) and returns EOF without resetting 'oneline'. The strbuf > still has the subject of the previous commit, and that is what is > given to insert_one_record(). > > * If an incomplete header line (such as "Date:") appears at EOF, after > matching "Author:", the first inner loop reads the "Date:" line into > 'oneline', sets feof(stdin), and returns 0. Because '.len' is > non-zero, the loop runs again; both that iteration and the second > inner loop see feof(stdin) and return EOF without resetting > 'oneline'. insert_one_record() therefore records the discarded > "Date:" header as the commit's subject. Right. After reading the first two paragraphs I already suspected the second issue, which is the more obvious one. But the first issue can of course also happen. > diff --git a/t/t4201-shortlog.sh b/t/t4201-shortlog.sh > index 10c43e6e75..dc1b175653 100755 > --- a/t/t4201-shortlog.sh > +++ b/t/t4201-shortlog.sh > @@ -447,4 +447,33 @@ test_expect_success 'unknown revision options are reported correctly' ' > test_grep "unknown option .*--no-such-option" err > ' > > +test_expect_failure 'shortlog from stdin with incomplete Author line at EOF' ' Naturally we could introduce all of these tests as `test_expect_success` by manually resetting the line, and we could then drop all of those resets in the commit that does the change in `strbuf_getline_lf()`. But in the end the result is the same anyway, so... *shrug* Patrick