FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
security: validate CLI paths/args in dev tools (SonarCloud S2083/S8707/S8705) (#2723)
Dylan M. Taylor757618687893
diff --git a/crates/av1/tools/extract_tables.py b/crates/av1/tools/extract_tables.pyindex 83c4e2c9f..5ee6d95cf 100644--- a/crates/av1/tools/extract_tables.py+++ b/crates/av1/tools/extract_tables.py@@ -17,6 +17,16 @@ dimensions; the element type is the narrowest of u8/i8/u16/i16/i32 that holds evimport osimport reimport sys+from pathlib import Path+++def _spec_path(arg):+ """Resolve a CLI path argument and require it to be an existing regular file."""+ path = Path(arg).resolve()+ if not path.is_file():+ sys.exit(f"not a readable file: {arg}")+ return path+root = sys.argv[1]files = sorted(f for f in os.listdir(root) if f.endswith(".md"))diff --git a/crates/dnx/tools/extract_tables.py b/crates/dnx/tools/extract_tables.pyindex 56d73a6e1..2e120cc93 100644--- a/crates/dnx/tools/extract_tables.py+++ b/crates/dnx/tools/extract_tables.py@@ -14,8 +14,18 @@ prefix code."""import reimport sys+from pathlib import Path-text = open(sys.argv[1], encoding="utf-8").read()++def _spec_path(arg):+ """Resolve a CLI path argument and require it to be an existing regular file."""+ path = Path(arg).resolve()+ if not path.is_file():+ sys.exit(f"not a readable file: {arg}")+ return path+++text = open(_spec_path(sys.argv[1]), encoding="utf-8").read()lines = text.split("\n")diff --git a/crates/hevc/tools/extract_tables.py b/crates/hevc/tools/extract_tables.pyindex 8b9fa3979..6ee5759df 100644--- a/crates/hevc/tools/extract_tables.py+++ b/crates/hevc/tools/extract_tables.py@@ -13,8 +13,18 @@ initType following Table 9-4, default scaling lists (Table 7-6), intraPredAngle"""import reimport sys+from pathlib import Path-text = open(sys.argv[1], encoding="utf-8").read().replace("−", "-").replace("–", "-")++def _spec_path(arg):+ """Resolve a CLI path argument and require it to be an existing regular file."""+ path = Path(arg).resolve()+ if not path.is_file():+ sys.exit(f"not a readable file: {arg}")+ return path+++text = open(_spec_path(sys.argv[1]), encoding="utf-8").read().replace("−", "-").replace("–", "-")lines = text.split("\n")diff --git a/crates/vp8/tools/extract_tables.py b/crates/vp8/tools/extract_tables.pyindex 5f7710e93..2daaf87e4 100644--- a/crates/vp8/tools/extract_tables.py+++ b/crates/vp8/tools/extract_tables.py@@ -11,8 +11,18 @@ emitted flat (row-major, as printed) with its element count checked against the"""import reimport sys+from pathlib import Path-text = open(sys.argv[1], encoding="utf-8").read()++def _spec_path(arg):+ """Resolve a CLI path argument and require it to be an existing regular file."""+ path = Path(arg).resolve()+ if not path.is_file():+ sys.exit(f"not a readable file: {arg}")+ return path+++text = open(_spec_path(sys.argv[1]), encoding="utf-8").read()cut = text.find("\n20. Attachment One")if cut < 0:sys.exit("section 20 not found")diff --git a/crates/vp9/tools/extract_tables.py b/crates/vp9/tools/extract_tables.pyindex bdd59bb7b..d3870f530 100644--- a/crates/vp9/tools/extract_tables.py+++ b/crates/vp9/tools/extract_tables.py@@ -12,8 +12,18 @@ element count checked against the declared dimensions."""import reimport sys+from pathlib import Path-text = open(sys.argv[1], encoding="utf-8").read().replace("−", "-").replace("–", "-")++def _spec_path(arg):+ """Resolve a CLI path argument and require it to be an existing regular file."""+ path = Path(arg).resolve()+ if not path.is_file():+ sys.exit(f"not a readable file: {arg}")+ return path+++text = open(_spec_path(sys.argv[1]), encoding="utf-8").read().replace("−", "-").replace("–", "-")lines = [l for l in text.split("\n") if "Copyright" not in l and "VP9 Bitstream & Decoding Process Specification" not in l]text = "\n".join(lines)diff --git a/sonar-project.properties b/sonar-project.propertiesindex c8ed2b47d..bd9f6a3f9 100644--- a/sonar-project.properties+++ b/sonar-project.properties@@ -1,2 +1,3 @@sonar.projectKey=storytold_filmcraftsonar.organization=storytold+sonar.coverage.exclusions=**/tools/**,**/docs/**,**/examples/**