From 000a266e69c714848b2e0b2836964a92bc1c5965 Mon Sep 17 00:00:00 2001 From: Scott Lee Date: Wed, 19 Feb 2025 10:29:47 -0800 Subject: [PATCH] metrics_xml_format: check the XML path against realpath metrics_xml_format checks the given file path to ensure that it's an XML under tools/metrics with the following steps. 1. convert the input file path as a real path. 2. check the real path starts with GetPrimarySolutionPath() + "/tools/metrics" This doesn't work as intended if GetPrimarySolutionPath() returns a symblink. This patch converts GetPrimarySolutionPath() as a realpath to ensure it runs the check based on the realpath of the git checkout. Bug: 396182402 Change-Id: I3207eba7ed52d09a01b38d65fcf7c314622d95cb Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6279842 Auto-Submit: Scott Lee Commit-Queue: Gavin Mak Reviewed-by: Gavin Mak --- metrics_xml_format.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/metrics_xml_format.py b/metrics_xml_format.py index e249364e5..51898db3f 100755 --- a/metrics_xml_format.py +++ b/metrics_xml_format.py @@ -12,6 +12,7 @@ import sys def GetMetricsDir(top_dir, path): + top_dir = os.path.realpath(top_dir) metrics_xml_dirs = [ os.path.join(top_dir, 'tools', 'metrics', 'actions'), os.path.join(top_dir, 'tools', 'metrics', 'histograms'), @@ -45,10 +46,12 @@ def FindMetricsXMLFormatterTool(path, verbose=False): if not top_dir: log('Not executed in a Chromium checkout; skip formatting', verbose) return '' + xml_dir = GetMetricsDir(top_dir, path) if not xml_dir: log(f'{path} is not a metric XML; skip formatting', verbose) return '' + # Just to ensure that the given file is located in the current checkout # folder. If not, skip the formatting. if not os.path.realpath(path).startswith(os.path.realpath(top_dir)):