From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.208.72 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796055734; b=LUU+lalwUBDSddswrVf2MU5Szv7NHMqUxT2vo2fwVhE+uAzoVXAqxMSs+rSvDQrKkGfq GUi7FdR1G7moxChGzXcGgG24Grn28rsUibWDd+uX1O2WuYk0gCZzwiO/UKI4YDbx7DZ4s y3oPnnAHuDVDfo2gsMXK8Vko+erGxAapd5SjcO8v6hHDDEdZNFKmmi/FJ7KiDRQ9EjJOu p0twglC/7mT3S2+0+sLBrv5fVWKFTMPXjEG3Jc/F99YXFBv+Tdnx60RIOVlrWYhhHnRO2 vhHLIjDmCTpE20pRX+XSci9GX7k+LRH95qii86lJGSTrCd90Q0oxlyM8aeKyFf3XwEg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796055734; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Received:Date:In-Reply-To:Mime-Version: References:X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=Eg9my6ygKgvXjFpSGkebSYtUozYD1UTJNEDqIACoXyQ=; b=NF3Sr/2NRyGY553yG0fYEIgRy9QW62YvHBlZ5YkV0v+RK9+D8gIv+iEgCMhHJLYRnQXQ 9djUU09lIQ6gC8VUxRVgDmUGP4a8yEkhKynS6XZkYpO4lT2Nl8ZsV3xU6IpA6u89TeKhq dWiw0ZpYdMrDwcagwvW26WC96n0F0ZXR/3SAjvQZ386CEC5Udwu7mwgs8OSsDzQUjX5us gWyePi1ucDNJD1cEA8MI+2tjZjJSLzXkSZS2b1KYX3Kyrexp/l2JiywLybdWEfQxgN/30 utxHovb5UZQvKOY4u9KSYmBYc3/LYU7nI5yyYjtBL+lOmZbfH4797OCakDFYHs51amw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--dmnk.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=pAvDmLOW; arc=none smtp.remote-ip=209.85.208.72 Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4ABC2606A325 for ; Mon, 30 Nov 2026 16:22:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4ABC2606A325 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--dmnk.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=pAvDmLOW Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-6b3f6d9827eso3720235a12.2 for ; Mon, 30 Nov 2026 08:22:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796055733; x=1796660533; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Eg9my6ygKgvXjFpSGkebSYtUozYD1UTJNEDqIACoXyQ=; b=pAvDmLOW3M9dTRl8o/Gw8cMPyVD/LVD0uU1eENTlRMaQRdh3cuK+8L7U7JTq8IlavA cN7lqEtJDBX73QT3L1QJSCjbcLq4KHiVCgpKnodOI9aO7j1a+naDNBWo6+B/BeJZXz1M PNEbBzyUR7Ja8PoJ6lmLQqoCUKOPb0rm02xWoBZjqHBBFNrWQqNWTStTNTd+Ger+Fp/D iuHZSPbymSGGGYKrlQW8508Uu1uNlwyz13Dh5Moq5lS3MHKpeAIRJ3o1RqBgrXUSSJJN raw1E7zZSKsD8EIBDmYJpSjvkhK3tZx0MOrR4us5StgUHmZucYgyeRFH7dTkWhAAQfJk 3Q3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796055733; x=1796660533; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Eg9my6ygKgvXjFpSGkebSYtUozYD1UTJNEDqIACoXyQ=; b=T3hil2s9zgdZ4XvuQCNtYqxzJSmb+hknkjB0pLDNnTFn1OtSCxRJ89exVITJ51EpPi H20PFBiqwmXDB5GhorqKjbx/tlpT3BaRzD7iKaoJLCqMDv/8AuGfu2GCaeEehYm73OV1 eS17bTjN1ejVL4j0bLliOde82SGhu+dFHaNCWnHNq3EEv+pbqip1+XAUl/M6ZOfmE8ol MaDUgUczY9NlbewCXK1PEF2SoekMFlcKRENzIzn8SUDvO6dwRs/sFyfKqLbLcfCiST4R 9BNF9vSF1kqzod1Im2DmiyhpKLh3JX2/zmmbn0zP+cN0aLobB9B7gJv1ngXKbdCy4gi3 Hc4A== X-Gm-Message-State: APuU4Z9hk6GfByOY9Q8/OcJb8pO4V5OJLn8izORE881XYgDx48V5k5YN pcGGHtJcA68avIV/ADvpr5ecD2A5bqXmo01/0Lx55a561x8Yi8Np76mDHJoxR23FMk3zyPPDEJy J/oQrhOeVamyR2U04juDJ2nAdRwgs4+mHp0N1j1Pywhx7KousbvPBuOeZM3lGAe44+1TFBFg8un 0z3eXNC8gSh4D/UCvf1E3O4A== X-Received: from edcnu17-n1.prod.google.com ([2002:a05:6402:c511:10b0:6bb:bfae:6e7d]) (user=dmnk job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6402:210e:b0:6b8:6e5d:31c8 with SMTP id 4fb4d7f45d1cf-6ba37d34b4emr24716218a12.16.1796055732449; Mon, 30 Nov 2026 08:22:12 -0800 (PST) Date: Mon, 30 Nov 2026 17:22:11 +0100 In-Reply-To: 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 References: X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog Message-ID: <20261130162211.3369007-1-dmnk@google.com> Subject: [PATCH v2] filter-branch: check hex oids in state-branch map From: Dominik Maier To: git@vger.kernel.org Cc: Junio C Hamano , Grant Moyer , Michele Locati , Patrick Steinhardt , dmnk+artist@google.com Content-Type: text/plain; charset="UTF-8" Loading a state branch in git-filter-branch writes commit-map files using unvalidated names from filter.map, allowing entries with slashes or ".." to write outside the temporary map directory. When --state-branch restores filter.map, each "from:to" line is split and written directly to "../map/$from_commit" without checking either side. Read entries with "IFS= read -r" and require the source ID to be non-empty lowercase hex and the target field to contain only lowercase hex digits and spaces (it may be empty for pruned commits, or list multiple space-separated commits expected by $(map "$parent")). Signed-off-by: Dominik Maier --- Changes in v2: - Note in the commit message why "$to_commit" accepts spaces for multi-commit mappings read via $(map "$parent") (Junio C Hamano). - Rebase onto master (86e79b2795). - v1: https://lore.kernel.org/git/20261119192316.2688525-1-dmnk@google.com/ git-filter-branch.sh | 14 ++++++++++++-- t/t7003-filter-branch.sh | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/git-filter-branch.sh b/git-filter-branch.sh index 9aa07be6e..fbf7882a7 100755 --- a/git-filter-branch.sh +++ b/git-filter-branch.sh @@ -298,13 +298,23 @@ then git show "$state_commit:filter.map" >"$tempdir"/filter-map || die "Unable to load state from $state_branch:filter.map" - while read line + while IFS= read -r line do case "$line" in *:*) from_commit=${line%:*} to_commit=${line#*:} - echo "$to_commit" >../map/"$from_commit";; + case "$from_commit" in + "" | *[!0-9a-f]*) + die "Unable to load state from $state_branch:filter.map" + ;; + esac + case "$to_commit" in + *[!0-9a-f\ ]*) + die "Unable to load state from $state_branch:filter.map" + ;; + esac + printf '%s\n' "$to_commit" >../map/"$from_commit";; *) die "Unable to load state from $state_branch:filter.map";; esac diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh index 801cc83e5..cab97e0e0 100755 --- a/t/t7003-filter-branch.sh +++ b/t/t7003-filter-branch.sh @@ -560,4 +560,23 @@ test_expect_success 'filter-branch handles ancestor rewrite' ' git diff-tree HEAD^ ancestor ' +test_expect_success 'state-branch rejects non-hex or path-traversing filter.map entries' ' + test_when_finished "rm -f escaped && git update-ref -d refs/heads/bad-state" && + bad_blob=$(printf "../../escaped:injected\n" | git hash-object -w --stdin) && + bad_tree=$(printf "100644 blob %s\tfilter.map\n" "$bad_blob" | git mktree) && + bad_commit=$(echo "bad state" | git commit-tree "$bad_tree") && + git update-ref refs/heads/bad-state "$bad_commit" && + test_must_fail git filter-branch -f --state-branch refs/heads/bad-state HEAD 2>err && + test_grep "Unable to load state from refs/heads/bad-state:filter.map" err && + test_path_is_missing escaped && + + head_oid=$(git rev-parse HEAD) && + bs_blob=$(printf "%s\\\\:%s\n" "$head_oid" "$head_oid" | git hash-object -w --stdin) && + bs_tree=$(printf "100644 blob %s\tfilter.map\n" "$bs_blob" | git mktree) && + bs_commit=$(echo "backslash state" | git commit-tree "$bs_tree") && + git update-ref refs/heads/bad-state "$bs_commit" && + test_must_fail git filter-branch -f --state-branch refs/heads/bad-state HEAD 2>err && + test_grep "Unable to load state from refs/heads/bad-state:filter.map" err +' + test_done -- 2.56.1.911.g883d8bcb20-goog