From patchwork Tue Feb 6 09:49:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13546946 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E3A412880E for ; Tue, 6 Feb 2024 09:49:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707212988; cv=none; b=dLUiyNa/JPwOpxQnQ2ysThKa/6eqvHE4jmr7DsDRaK0/Ud3P9HSCd0ueGnx4AS/mdEUc8cLwGSat9qL9usTqnBvMiwdVy4rwvtW8v/J2kPzGS8IceriINYlHnNzyYMv/JsUySo0XmXLUOaiK+vxPGx4kMa6hMl+AsCPu8kQ083Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707212988; c=relaxed/simple; bh=UF1LtAtCg3Xw6aOmpz2Kn8rD8A25KkCrQgAaLydPfJQ=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=D4mAs/tnl/RdKogSRBa4UDAPcSmYlV6D4qXbkBuX4eRW4nEBM9GaWJBG9G/sDdgdFo5U90RAmTwjTnbC2OznOBUBTgzW3MNYSxpqoJlW/yU5Piw6P9YOTCx9Ti6Moul3eaSbjUSiptDW/kLaMPuL9LsP9WJdw9Tg/ymssZK2nNA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=b3zl0qHa; arc=none smtp.client-ip=209.85.221.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="b3zl0qHa" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-33b409fc4aeso1101145f8f.1 for ; Tue, 06 Feb 2024 01:49:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707212983; x=1707817783; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=sR/xfp1VY9CgeMC+I7NGlzGCLSwaZNZyqDSar95wmrc=; b=b3zl0qHaH1VSGwoWtb9I2qwolE+ZbC95rZOMoi84xOt5vIOu8i98shO49950WT+WRM 7QJD+0IlYVSEfFNCEVJWGjXQYz61A1C2vVlEHCplnopkyW1cdNF+nT4f6Tf8xEJlpmP/ ICrWjIn6HLkT9Q3NwhLz3ofizilDCwV/xqs0I93Vrwu+UA1KGgdZjw34k4oY4ptixznZ OgPJlZe8g5V9nlvepJLBOcxHC89NA8ChQuW8kHrvHiJUEgDWStXEbiiwllpaiSSnayaj 2M2DaDUKzXKOIM0ZFp5BPs0b7rKNNLWI8cFGw0nekQ6PLtvf52bT2cwsxtVCgLoCXihM 6Uew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707212983; x=1707817783; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sR/xfp1VY9CgeMC+I7NGlzGCLSwaZNZyqDSar95wmrc=; b=kGtwts+TgFYhsJFPZsgpzBk54JIaSFGSPcaXlREkmVuGneOicEn3H8fqrih0xgPWMD UuJ366cJSA2QNF5DqRhupFnvcYFH8nUEeb/FN83/PmodUD6/Lqjb7ZmsycWUTS3uCv3P gEbGaziLICOMlOIRv8hqVvVv7uNoF4jBMnnK9ZpldxXFUaxIJXI1zfitx3n5ehHXG3lD jhelAt6cghgpJVAccx36nr0ploUIAOf1s9JvXZzxYZLYxtX4SuOjbpDWkaiicPq5S2Yc gFfbEvDJShaE/xYmV4ue5lWQovDKDjTEX8ksfjbbi4EO4zN2Slh3RHd7FXatYDG4H3LQ 7/9w== X-Gm-Message-State: AOJu0YwZ6iBtZFjSdrlSN2z2+/OFUvpr0Q9T8J1euGmHtAtS/itq8sYG cj8Vm1UtwbgWtkx/8Yn2vEkyZlFmYwpwhZ5Q/c/5OwPtXVFOaXHFjdYv2PG3 X-Google-Smtp-Source: AGHT+IHxHbod8aEUhkl3CJShL/ikn871qzlPM+MYHFVJ2lYNpYMQgSTlNZtqj+ALL3wqEL3VgLLJCQ== X-Received: by 2002:a5d:4cc8:0:b0:33b:381d:a71e with SMTP id c8-20020a5d4cc8000000b0033b381da71emr741431wrt.17.1707212983191; Tue, 06 Feb 2024 01:49:43 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r21-20020adfa155000000b0033b2497fdaesm1637634wrr.95.2024.02.06.01.49.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 01:49:43 -0800 (PST) Message-ID: In-Reply-To: References: Date: Tue, 06 Feb 2024 09:49:38 +0000 Subject: [PATCH 1/4] merge-tree: fail with a non-zero exit code on missing tree objects Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin When `git merge-tree` encounters a missing tree object, it should error out and not continue quietly as if nothing had happened. However, as of time of writing, `git merge-tree` _does_ continue, and then offers the empty tree as result. Let's fix this. Signed-off-by: Johannes Schindelin --- merge-ort.c | 7 ++++--- t/t4301-merge-tree-write-tree.sh | 10 ++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/merge-ort.c b/merge-ort.c index 6491070d965..c37fc035f13 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -1659,9 +1659,10 @@ static int collect_merge_info(struct merge_options *opt, info.data = opt; info.show_all_errors = 1; - parse_tree(merge_base); - parse_tree(side1); - parse_tree(side2); + if (parse_tree(merge_base) < 0 || + parse_tree(side1) < 0 || + parse_tree(side2) < 0) + return -1; init_tree_desc(t + 0, merge_base->buffer, merge_base->size); init_tree_desc(t + 1, side1->buffer, side1->size); init_tree_desc(t + 2, side2->buffer, side2->size); diff --git a/t/t4301-merge-tree-write-tree.sh b/t/t4301-merge-tree-write-tree.sh index 7d0fa74da74..4ea1b74445d 100755 --- a/t/t4301-merge-tree-write-tree.sh +++ b/t/t4301-merge-tree-write-tree.sh @@ -950,5 +950,15 @@ test_expect_success '--merge-base with tree OIDs' ' git merge-tree --merge-base=side1^^{tree} side1^{tree} side3^{tree} >with-trees && test_cmp with-commits with-trees ' +test_expect_success 'error out on missing tree objects' ' + git init --bare missing-tree.git && + ( + git rev-list side3 && + git rev-parse side3^: + ) | git pack-objects missing-tree.git/objects/pack/side3-tree-is-missing && + side3=$(git rev-parse side3) && + test_must_fail git --git-dir=missing-tree.git merge-tree $side3^ $side3 >actual && + test_must_be_empty actual +' test_done From patchwork Tue Feb 6 09:49:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13546947 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D238812D17A for ; Tue, 6 Feb 2024 09:49:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707212988; cv=none; b=njGGmVBWXr4OSsr3FDkVzJmeHda+bEfgHLl2EOYHE9WByqFImipHso9HxcNw7SKCQRiVCtjWayE8fP38smfC35BuTiSFpS5mQ31KhDj6CgDUoQzFO8ya0g46nv7lAbe6XnlXZbFuY0lAfjv4bD8rvYDrNVw5RoRpWEbYqGci3/E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707212988; c=relaxed/simple; bh=Xq7WRXhxo0C1kRAmZ99K0pnF6HJm4Bw5bwfBCsQ5cn4=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=QT3DsQAg5pyxxZQmg6eNnKwfJwBMyV+2hqrcdArhyMWKX2MafY2UVAjYievjdndmCVr6/L5dcvpeLxy2Y7EygOvdQvhjdBFbu+Uz3Ts+BlDR+Ez/3dWV03AebcCFy1jzPi7HPJDn+NpEUnOJE9gFmyzAnFwuMVd6dunocFmHmYw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZS3WqAHW; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZS3WqAHW" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-40fe03cd1caso7515305e9.0 for ; Tue, 06 Feb 2024 01:49:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707212985; x=1707817785; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=3+i8PkXYJCTRN8cYGZeTF3cwl+HgYBrV1XX86X8PXc4=; b=ZS3WqAHWmJqqDIEj1EM1FSDoDG4fBWM6Ets73ZVN2CBINJn9NC7NXs4IUAl9WfY3o5 t5AXVKkQw3JvSFhCzGHQB20+PWncps9jxYqaQa4/gzvj0nyVakGbFVPhK045mLM9DTND b3EScBXTR45HLjLJJqHczJG3Y+lYs2uz9XvtSNnFFe2+sGHhMUNKwBYKU/D3Sr9D0LXK B25/ZB03veFT9MOoVq/xnqWeYtyIfdyp6hqz5btYy9ir6QabHHQA9EvnS1S0iATuJbv4 MBw5EZ+ayUfSRiQU58aIaAFC39Z5d6oDAi3rxAjxJm3wliAmgFOBVmymLdxD5QEHYFqF r/WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707212985; x=1707817785; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3+i8PkXYJCTRN8cYGZeTF3cwl+HgYBrV1XX86X8PXc4=; b=ct//q98UlL5UeDnQQbaSOIp+UsPvGJNPwkFnh/rKrhRIQtEP1FYzitJ4LlJeC5horP Wf/fBV5D6L0QlizH5PRr3w0fHh8fYFk8dro9JG8CMK5Fj2vIqtMDDK60lLSBh9DsX5Wc JueutQt0aUkfzJGZDmeOshaiGXaT01eB4HNTiVAei037lA2+vIERFM2Q9Zsko2/OB2i4 fmRMoMgc3kRh1k77Ixem2qZSvx4MCOLaholuHN6ZW60487uOVxpasQ/7hD87gkg/nGSa HxlIgql260161/MhS1z49Kvp/c0/b3olsMGf3ozpgOVnGUVP+kRXXnNnH7HTXcDxkDs8 JJUw== X-Gm-Message-State: AOJu0YzlQ7BXa1cYVAlb72dC+c+1syDkIMYqKvEtkzOu42Fp3Ru4GLuX MfcmHzkfM1Hecz68QD+EYB91Y4H/PLMRjqmnUN16hKrBN3Y93OgzncGFgapA X-Google-Smtp-Source: AGHT+IHNFwTQhESqdsmyyPot0gMSjHWRkTlgZDW5fH5tEcRzHeleYL8Kcfq+8RMSg04x6QMdDeRz3Q== X-Received: by 2002:a05:600c:1d2a:b0:40e:bfbf:f368 with SMTP id l42-20020a05600c1d2a00b0040ebfbff368mr1848598wms.2.1707212984626; Tue, 06 Feb 2024 01:49:44 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f11-20020a05600c154b00b0040fafd84095sm1428314wmg.41.2024.02.06.01.49.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 01:49:43 -0800 (PST) Message-ID: <3e5b787fc03493b1feaada7ef0011ca2d33f8820.1707212981.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 06 Feb 2024 09:49:39 +0000 Subject: [PATCH 2/4] merge-ort: do check `parse_tree()`'s return value Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin The previous commit fixed a bug where a missing tree was reported, but not treated as an error. This patch addresses the same issue for the remaining two callers of `parse_tree()`. This change is not accompanied by a regression test because the code in question is only reached at the `checkout` stage, i.e. after the merge has happened (and therefore the tree objects could only be missing if the disk had gone bad in that short time window, or something similarly tricky to recreate in the test suite). Signed-off-by: Johannes Schindelin --- merge-ort.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/merge-ort.c b/merge-ort.c index c37fc035f13..79d9e18f63d 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -4379,9 +4379,11 @@ static int checkout(struct merge_options *opt, unpack_opts.verbose_update = (opt->verbosity > 2); unpack_opts.fn = twoway_merge; unpack_opts.preserve_ignored = 0; /* FIXME: !opts->overwrite_ignore */ - parse_tree(prev); + if (parse_tree(prev) < 0) + return -1; init_tree_desc(&trees[0], prev->buffer, prev->size); - parse_tree(next); + if (parse_tree(next) < 0) + return -1; init_tree_desc(&trees[1], next->buffer, next->size); ret = unpack_trees(2, trees, &unpack_opts); From patchwork Tue Feb 6 09:49:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13546949 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 837B112C803 for ; Tue, 6 Feb 2024 09:49:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707212990; cv=none; b=j8tbdjPypzVPm51UXqgbxlJIAH5LwxhkWUDPo7tmRYt+VB/H1KsTqDX4VvNoLTaF7rVtQpcZnoyz01hSDTVMEYDMHJkJHEBGNMu0JJMxrdLi4j7DMeI4Hvq5peIy9RFFOxMrwN8e145m2c4QT6aAYL8dYI7nTDN2c9JVLvZpmq0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707212990; c=relaxed/simple; bh=Og36+Y9Y1mkcIZf7hhF7LpKF7o/BSNCJBY9g3T1XPOw=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=hhMJ9BOYHJD4bA1gv7p8JL41mD6fv45pFz8+vcxJDWxNh2t+5/8M3G+PTEa66FO1ix7yQOnKGmY5pvpcwUL8hd64flpakaWnCE+i1jjGn7llGwRXb+ffEZLV+RXmfEcYylcmb+lQMMXAIT1lKoF5FUoE0Be6gK/MnlYbFedeMcM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=EQRi/vhM; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EQRi/vhM" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-40fe6c66c3fso2191515e9.2 for ; Tue, 06 Feb 2024 01:49:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707212985; x=1707817785; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=CDg6C0kp0tIphGPIcDJqqlIdDG7TgaRDGAT8tV9t48Y=; b=EQRi/vhMybjBqjcHKaxJW+XWGTHuDchwBo8kVbSp+g958TgGO+Q7xqow+yfjwpFaNc vtN+EeZrAGdS5AssX7glIeaKdnLEijMo62IoqxOgqp14Ks9rxJxY9eAMRts8fZHYIXG0 JI7tIv4nbJJfjmMyGdkQ1Da8sl+xcbAPQ02fpmfXMygJQkM2DNvVGfTk7l/CYXsE+sxM XsHqNmr2dOoVs8tptKBvLnRoEwgocK+2b+76c47PiAwnezZiH3IbFZT69So+0O1VemYd nrze8MJ6U0Ti7iQVc3fNhM3KI+KP39pGAUAP2VhT8cqqoJJsmfXbVVSvacCqadiQYb9B Kevw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707212985; x=1707817785; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CDg6C0kp0tIphGPIcDJqqlIdDG7TgaRDGAT8tV9t48Y=; b=J7wZY8TQut/akUoajB7PX3+23TZES3xhyPkMnKolv316XayYGuOhYn5UmM0b+JEQUQ +I2hbViGeMgwL8syWazaZKe2jgGhweMHBgZB2DSPNeYeHOKMGc4sjms2/xoMggBovXwP mceZyM2DxyOU4HwH9bvDX+sUREG72IOBYKhY2EAlLhASLlP3145/nzC5N5Yqcafse555 FSA2CrBbXdlLNdYtB9rvAF7KXR/2Ej6L6IljTvInWcNcK2JqB6lj9SMGttnv7rt2aUFi 91WtaR+aT8US6EfD970iSBPFpFPkqiKnN3EvlcdcoXm51v48aNEwzEDXP0Kw9QIk6yTL /kbg== X-Gm-Message-State: AOJu0Yxr7ceGFR08ddzNL8bdnChqj+njix5FhpxVx5hH+EIXY9/debmE VTAOiWpzMCfnmhJFRjDyUbGHJBAri/no6VaH6iTU+OK2tYla9HLMtp5z6fcx X-Google-Smtp-Source: AGHT+IHQ9gQ8zKo/h+jnQbD3a6ob5gk06mil8JYPtGPhEyMKIXayKCAcqQ2Gt19Gjpywssbi3Qyd8g== X-Received: by 2002:adf:edd0:0:b0:33b:179d:d9aa with SMTP id v16-20020adfedd0000000b0033b179dd9aamr727898wro.26.1707212985121; Tue, 06 Feb 2024 01:49:45 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u13-20020a5d6dad000000b0033b1b01e4fcsm1659035wrs.96.2024.02.06.01.49.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 01:49:44 -0800 (PST) Message-ID: <85d3e6728714606c3eac42a561ae89b61457647b.1707212981.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 06 Feb 2024 09:49:40 +0000 Subject: [PATCH 3/4] t4301: verify that merge-tree fails on missing blob objects Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin We just fixed a problem where `merge-tree` would not fail on missing tree objects. Let's ensure that that problem does not occur with blob objects (and won't, in the future, either). Signed-off-by: Johannes Schindelin --- t/t4301-merge-tree-write-tree.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/t/t4301-merge-tree-write-tree.sh b/t/t4301-merge-tree-write-tree.sh index 4ea1b74445d..86807a57d4d 100755 --- a/t/t4301-merge-tree-write-tree.sh +++ b/t/t4301-merge-tree-write-tree.sh @@ -961,4 +961,18 @@ test_expect_success 'error out on missing tree objects' ' test_must_be_empty actual ' +test_expect_success 'error out on missing blob objects' ' + seq1=$(test_seq 1 10 | git hash-object -w --stdin) && + seq2=$(test_seq 1 11 | git hash-object -w --stdin) && + seq3=$(test_seq 0 10 | git hash-object -w --stdin) && + tree1=$(printf "100644 blob %s\tsequence" $seq1 | git mktree) && + tree2=$(printf "100644 blob %s\tsequence" $seq2 | git mktree) && + tree3=$(printf "100644 blob %s\tsequence" $seq3 | git mktree) && + git init --bare missing-blob.git && + test_write_lines $seq1 $seq3 $tree1 $tree2 $tree3 | + git pack-objects missing-blob.git/objects/pack/side1-whatever-is-missing && + test_must_fail git --git-dir=missing-blob.git merge-tree --merge-base=$tree1 $tree2 $tree3 >actual && + test_must_be_empty actual +' + test_done From patchwork Tue Feb 6 09:49:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13546948 Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9112B12D777 for ; Tue, 6 Feb 2024 09:49:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707212990; cv=none; b=eXG44qUb90WCa9+pvoH9YXGoW9wkfYUX1JreNmv+fTVlcwGmTWciwVUtHwMsBvgKD+nvN4FqLQiEg5dj2IjTBh8JBPrcCsiq6guTGfztXBeXSIZD617pRGAOe31uJef70FaauGN3C44nsrABtOuPtQROUDib0FaAZawlzwBwbk4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707212990; c=relaxed/simple; bh=6aEUjPpwEbnaYV3kXz/jrdo3l6oDJIDXkOyJXDDAdhY=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=jTOfA0Osl0pDsup0+tsbv6t/u+uyPkXN4jPmCWrylbPbjizwtnGy6PclBMMv7ni/hJrbRORWokkb/Macv8A6tdpB0MDAPLGEk9JoeWLnFAKQAli/blgbtWXMmUz1AWPG/Mrj8SJ9s53BvReqv/wwl3FoyFkhINiclZx/jvMRH9Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=a4CnDA1t; arc=none smtp.client-ip=209.85.208.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="a4CnDA1t" Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-2d093cb1ef3so39349761fa.3 for ; Tue, 06 Feb 2024 01:49:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707212986; x=1707817786; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=Ad2cPhi69GjEqH2CIRTbzXTU/IPqUZKRLZ5wvFohiWs=; b=a4CnDA1tcQRc1knbhwZSQ0v59YuYYZBO2Tmjj8wsobkH4hrqhmMcpMVSYKohWGmGp8 f1IZG8qaPr7cHv9KLd0Km44BEaxhXijqQQjSmXRR3KRPeUVnnyQzwWD6w7bRCnZpPc51 DRB7591ZV0GvH/Aj/husHZorJHImq0LtXKixP8BqcgFQ24wjkhP2IFAlwHTBgKv/Kx4U ywV0XVzg7omKWgKyhJ2VgbWWoCkzqUpv4ZQz/0V/xI3EvAIttAzx48nseH4Tlx1GC8Ol VrmSgLIgdgMIqhQDhMYnqIP62riAHG9ZOFOnUFHzzT3r14oPztZvbGOnQgTHPScZ9LEy N99w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707212986; x=1707817786; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ad2cPhi69GjEqH2CIRTbzXTU/IPqUZKRLZ5wvFohiWs=; b=PAfXi5PHK0dU0mL0JNeEgOaeG0PGIsf661XQgj01Rbx00AJQdLFF5jnvGRs/pQSpcm i4bjOrH9UBogQWgchWt9kBeu/3vvNjvVnnYQU3OzKBcuXRaJtMCreMekk7k5aJue3bHo 43OnO7C41mS6PWAQ/IOoncCAiDs6wLSi0DWFg7S9iKGUkIH26EZHb/00cRWksYdjKmjO Ycs2VIZ2H9Cfk4PGKMdQelYvBAaBPbzsrMWa3s/IpQFmGOKcZzlUlby1dbYjuRqBkv1m re9TVvGYEE0drYzjcP49tZYvxZR7GCaGx8mptCw1lJAOCY+5bS4sP9IXCvr4+ZeMq4kS WqnA== X-Gm-Message-State: AOJu0YwvDBDLRMcYOLK+m7G3BgpeZ8b+7Mfmk8guly129Al3qw6a8UV2 TS0JBdWtVLDNQWiPG9pc+fibGgbTA+8RLIM1tQYItggnkZLuq5kR7zZbghB+ X-Google-Smtp-Source: AGHT+IEWAs4j44DkoboHtnWCjSosoXd9dpm2b1wcyjUfpX0VgwolRMAmTvsjmB+ka68OFohMfedooA== X-Received: by 2002:ac2:410a:0:b0:511:4f21:4517 with SMTP id b10-20020ac2410a000000b005114f214517mr1576623lfi.33.1707212986357; Tue, 06 Feb 2024 01:49:46 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f17-20020adfdb51000000b00337d6f0013esm1627807wrj.107.2024.02.06.01.49.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 01:49:45 -0800 (PST) Message-ID: <93abd7000b81bbcd7f5422715b4bbb60c69a7cde.1707212981.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 06 Feb 2024 09:49:41 +0000 Subject: [PATCH 4/4] Always check `parse_tree*()`'s return value Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin Otherwise we may easily run into serious crashes: For example, if we run `init_tree_desc()` directly after a failed `parse_tree()`, we are accessing uninitialized data or trying to dereference `NULL`. Note that the `parse_tree()` function already takes care of showing an error message. The `parse_tree_indirectly()` and `repo_get_commit_tree()` functions do not, therefore those latter call sites need to show a useful error message while the former do not. Signed-off-by: Johannes Schindelin --- builtin/checkout.c | 19 ++++++++++++++++--- builtin/clone.c | 3 ++- builtin/commit.c | 3 ++- builtin/merge-tree.c | 6 ++++++ builtin/read-tree.c | 3 ++- builtin/reset.c | 4 ++++ cache-tree.c | 4 ++-- merge-ort.c | 3 +++ merge-recursive.c | 3 ++- merge.c | 5 ++++- reset.c | 5 +++++ sequencer.c | 4 ++++ 12 files changed, 52 insertions(+), 10 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index f02434bc155..84108ec3635 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -707,7 +707,8 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o, init_checkout_metadata(&opts.meta, info->refname, info->commit ? &info->commit->object.oid : null_oid(), NULL); - parse_tree(tree); + if (parse_tree(tree) < 0) + return 128; init_tree_desc(&tree_desc, tree->buffer, tree->size); switch (unpack_trees(1, &tree_desc, &opts)) { case -2: @@ -786,9 +787,15 @@ static int merge_working_tree(const struct checkout_opts *opts, if (new_branch_info->commit) BUG("'switch --orphan' should never accept a commit as starting point"); new_tree = parse_tree_indirect(the_hash_algo->empty_tree); - } else + if (!new_tree) + BUG("unable to read empty tree"); + } else { new_tree = repo_get_commit_tree(the_repository, new_branch_info->commit); + if (!new_tree) + return error(_("unable to read tree %s"), + oid_to_hex(&new_branch_info->commit->object.oid)); + } if (opts->discard_changes) { ret = reset_tree(new_tree, opts, 1, writeout_error, new_branch_info); if (ret) @@ -823,7 +830,8 @@ static int merge_working_tree(const struct checkout_opts *opts, oid_to_hex(old_commit_oid)); init_tree_desc(&trees[0], tree->buffer, tree->size); - parse_tree(new_tree); + if (parse_tree(new_tree) < 0) + exit(128); tree = new_tree; init_tree_desc(&trees[1], tree->buffer, tree->size); @@ -1239,10 +1247,15 @@ static void setup_new_branch_info_and_source_tree( if (!new_branch_info->commit) { /* not a commit */ *source_tree = parse_tree_indirect(rev); + if (!*source_tree) + die(_("unable to read tree %s"), oid_to_hex(rev)); } else { parse_commit_or_die(new_branch_info->commit); *source_tree = repo_get_commit_tree(the_repository, new_branch_info->commit); + if (!*source_tree) + die(_("unable to read tree %s"), + oid_to_hex(&new_branch_info->commit->object.oid)); } } diff --git a/builtin/clone.c b/builtin/clone.c index c6357af9498..4410b55be98 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -736,7 +736,8 @@ static int checkout(int submodule_progress, int filter_submodules) tree = parse_tree_indirect(&oid); if (!tree) die(_("unable to parse commit %s"), oid_to_hex(&oid)); - parse_tree(tree); + if (parse_tree(tree) < 0) + exit(128); init_tree_desc(&t, tree->buffer, tree->size); if (unpack_trees(1, &t, &opts) < 0) die(_("unable to checkout working tree")); diff --git a/builtin/commit.c b/builtin/commit.c index 781af2e206c..0723f06de7a 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -339,7 +339,8 @@ static void create_base_index(const struct commit *current_head) tree = parse_tree_indirect(¤t_head->object.oid); if (!tree) die(_("failed to unpack HEAD tree object")); - parse_tree(tree); + if (parse_tree(tree) < 0) + exit(128); init_tree_desc(&t, tree->buffer, tree->size); if (unpack_trees(1, &t, &opts)) exit(128); /* We've already reported the error, finish dying */ diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index 2d4ce5b3886..ba84d00deee 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -447,12 +447,18 @@ static int real_merge(struct merge_tree_options *o, if (repo_get_oid_treeish(the_repository, merge_base, &base_oid)) die(_("could not parse as tree '%s'"), merge_base); base_tree = parse_tree_indirect(&base_oid); + if (!base_tree) + die(_("unable to read tree %s"), oid_to_hex(&base_oid)); if (repo_get_oid_treeish(the_repository, branch1, &head_oid)) die(_("could not parse as tree '%s'"), branch1); parent1_tree = parse_tree_indirect(&head_oid); + if (!parent1_tree) + die(_("unable to read tree %s"), oid_to_hex(&head_oid)); if (repo_get_oid_treeish(the_repository, branch2, &merge_oid)) die(_("could not parse as tree '%s'"), branch2); parent2_tree = parse_tree_indirect(&merge_oid); + if (!parent2_tree) + die(_("unable to read tree %s"), oid_to_hex(&merge_oid)); opt.ancestor = merge_base; merge_incore_nonrecursive(&opt, base_tree, parent1_tree, parent2_tree, &result); diff --git a/builtin/read-tree.c b/builtin/read-tree.c index 8196ca9dd85..5923ed36893 100644 --- a/builtin/read-tree.c +++ b/builtin/read-tree.c @@ -263,7 +263,8 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix) cache_tree_free(&the_index.cache_tree); for (i = 0; i < nr_trees; i++) { struct tree *tree = trees[i]; - parse_tree(tree); + if (parse_tree(tree) < 0) + return 128; init_tree_desc(t+i, tree->buffer, tree->size); } if (unpack_trees(nr_trees, t, &opts)) diff --git a/builtin/reset.c b/builtin/reset.c index 4b018d20e3b..f030f57f4e9 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -119,6 +119,10 @@ static int reset_index(const char *ref, const struct object_id *oid, int reset_t if (reset_type == MIXED || reset_type == HARD) { tree = parse_tree_indirect(oid); + if (!tree) { + error(_("unable to read tree %s"), oid_to_hex(oid)); + goto out; + } prime_cache_tree(the_repository, the_repository->index, tree); } diff --git a/cache-tree.c b/cache-tree.c index 641427ed410..c6508b64a5c 100644 --- a/cache-tree.c +++ b/cache-tree.c @@ -779,8 +779,8 @@ static void prime_cache_tree_rec(struct repository *r, struct cache_tree_sub *sub; struct tree *subtree = lookup_tree(r, &entry.oid); - if (!subtree->object.parsed) - parse_tree(subtree); + if (!subtree->object.parsed && parse_tree(subtree) < 0) + exit(128); sub = cache_tree_sub(it, entry.path); sub->cache_tree = cache_tree(); diff --git a/merge-ort.c b/merge-ort.c index 79d9e18f63d..534ddaf16ba 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -4983,6 +4983,9 @@ static void merge_ort_nonrecursive_internal(struct merge_options *opt, if (result->clean >= 0) { result->tree = parse_tree_indirect(&working_tree_oid); + if (!result->tree) + die(_("unable to read tree %s"), + oid_to_hex(&working_tree_oid)); /* existence of conflicted entries implies unclean */ result->clean &= strmap_empty(&opt->priv->conflicted); } diff --git a/merge-recursive.c b/merge-recursive.c index e3beb0801b1..10d41bfd487 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -410,7 +410,8 @@ static inline int merge_detect_rename(struct merge_options *opt) static void init_tree_desc_from_tree(struct tree_desc *desc, struct tree *tree) { - parse_tree(tree); + if (parse_tree(tree) < 0) + exit(128); init_tree_desc(desc, tree->buffer, tree->size); } diff --git a/merge.c b/merge.c index b60925459c2..14a7325859d 100644 --- a/merge.c +++ b/merge.c @@ -80,7 +80,10 @@ int checkout_fast_forward(struct repository *r, return -1; } for (i = 0; i < nr_trees; i++) { - parse_tree(trees[i]); + if (parse_tree(trees[i]) < 0) { + rollback_lock_file(&lock_file); + return -1; + } init_tree_desc(t+i, trees[i]->buffer, trees[i]->size); } diff --git a/reset.c b/reset.c index 48da0adf851..a93fdbc12e3 100644 --- a/reset.c +++ b/reset.c @@ -158,6 +158,11 @@ int reset_head(struct repository *r, const struct reset_head_opts *opts) } tree = parse_tree_indirect(oid); + if (!tree) { + ret = error(_("unable to read tree %s"), oid_to_hex(oid)); + goto leave_reset_head; + } + prime_cache_tree(r, r->index, tree); if (write_locked_index(r->index, &lock, COMMIT_LOCK) < 0) { diff --git a/sequencer.c b/sequencer.c index d584cac8ed9..407473bab28 100644 --- a/sequencer.c +++ b/sequencer.c @@ -715,6 +715,8 @@ static int do_recursive_merge(struct repository *r, o.show_rename_progress = 1; head_tree = parse_tree_indirect(head); + if (!head_tree) + return error(_("unable to read tree %s"), oid_to_hex(head)); next_tree = next ? repo_get_commit_tree(r, next) : empty_tree(r); base_tree = base ? repo_get_commit_tree(r, base) : empty_tree(r); @@ -3887,6 +3889,8 @@ static int do_reset(struct repository *r, } tree = parse_tree_indirect(&oid); + if (!tree) + return error(_("unable to read tree %s"), oid_to_hex(&oid)); prime_cache_tree(r, r->index, tree); if (write_locked_index(r->index, &lock, COMMIT_LOCK) < 0)