From patchwork Wed Jan 3 06:22:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13509678 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A062F1799A for ; Wed, 3 Jan 2024 06:22:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none 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) header.d=pks.im header.i=@pks.im header.b="gbunOJ+g"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="NmtO6noT" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 88D895C01DC; Wed, 3 Jan 2024 01:22:15 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Wed, 03 Jan 2024 01:22:15 -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=fm2; t=1704262935; x=1704349335; bh=Y4tzJ45r/+ RjhrXXIK89PFK2Y+AZPkz7gE0HDvEkL1Q=; b=gbunOJ+gaNrC8a48t8NInxfwhv jQWytPcMXB/0oAoxFCr27CgdEcifG6FiglJR7+RoUoSCEfFKAb1dWeR1NBgjDBJ5 2KTjeCSVuBgkNygT+46dHP+wS3y+AoUtfrAq4vj54J8oinvTuAW45M3XYsAPuVyo i2Qq6/yM2M5NC/NLWGjk7Ju4U/WemizhcmphnuMjEg68MGRrvTudBS7CjJ8YhZk/ 8b7VkxRNiuD1DMgg86cpTaPQ6rIC6ZXueK4XSgMqa4Ypt+qY9VZUqMT3lN1mgNiz SAz++jiYguHXr3FvDm9MYwrw2YmsZpuTyrCFmWOCW8k2AeZiQlCB6+LTgyQg== 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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1704262935; x=1704349335; bh=Y4tzJ45r/+RjhrXXIK89PFK2Y+AZ Pkz7gE0HDvEkL1Q=; b=NmtO6noTJ9K1gwhh7T04IN9ImWSn1VY2bFk+kZ6sFQNq Zv7ILPEra+0QoiPt7S/13LTDrsyTf7O3Szg6FSoFX85sRjANlsIBLoAOldIoryYQ v6dFN2K6AsmNgB97C4rek6J8JIWOOX0Xyuk5Prl31roao53NtSQ5kHatmD1h5idL gYnehsw3WCseRjHqlFld6T3H+4xyrivhEnbxQmqGEcOUS7/ARxheQc03RQi2u0Tt BgG+8Opb0LOBALXzIUybfZdoxm4n/AwVcRx+8EaeXA4pg5AVJKoDGHtAR3CrOt6o DvxbANRS7K+1AzS4I1b5Lqftc/GM630XGlDyzKiHDw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdeggedgleeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedtnecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 3 Jan 2024 01:22:14 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 7bf19f5e (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 3 Jan 2024 06:19:49 +0000 (UTC) Date: Wed, 3 Jan 2024 07:22:13 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Han-Wen Nienhuys , Junio C Hamano Subject: [PATCH v3 1/8] reftable/stack: do not overwrite errors when compacting Message-ID: <1dc8ddf04a112c38f41d573a48dac3f99b4b51e9.1704262787.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: In order to compact multiple stacks we iterate through the merged ref and log records. When there is any error either when reading the records from the old merged table or when writing the records to the new table then we break out of the respective loops. When breaking out of the loop for the ref records though the error code will be overwritten, which may cause us to inadvertently skip over bad ref records. In the worst case, this can lead to a compacted stack that is missing records. Fix the code by using `goto done` instead so that any potential error codes are properly returned to the caller. Signed-off-by: Patrick Steinhardt --- reftable/stack.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/reftable/stack.c b/reftable/stack.c index 16bab82063..8729508dc3 100644 --- a/reftable/stack.c +++ b/reftable/stack.c @@ -801,18 +801,16 @@ static int stack_write_compact(struct reftable_stack *st, err = 0; break; } - if (err < 0) { - break; - } + if (err < 0) + goto done; if (first == 0 && reftable_ref_record_is_deletion(&ref)) { continue; } err = reftable_writer_add_ref(wr, &ref); - if (err < 0) { - break; - } + if (err < 0) + goto done; entries++; } reftable_iterator_destroy(&it); @@ -827,9 +825,8 @@ static int stack_write_compact(struct reftable_stack *st, err = 0; break; } - if (err < 0) { - break; - } + if (err < 0) + goto done; if (first == 0 && reftable_log_record_is_deletion(&log)) { continue; } @@ -845,9 +842,8 @@ static int stack_write_compact(struct reftable_stack *st, } err = reftable_writer_add_log(wr, &log); - if (err < 0) { - break; - } + if (err < 0) + goto done; entries++; }