From 281d92bfb594c26744051c187051346bb5fb1fa1 Mon Sep 17 00:00:00 2001 From: Arths17 Date: Tue, 24 Nov 2026 13:28:35 -0600 Subject: [PATCH] Read native audit JSON as UTF-8 Signed-off-by: Arths17 --- .github/workflows/ci.yml | 2 + CHANGELOG.md | 1 + scripts/audit/native.sh | 2 +- tests/audit/test_native_json.py | 85 +++++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 tests/audit/test_native_json.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d749344..b3421c8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,6 +52,8 @@ jobs: sh -n scripts/agent-queue.sh scripts/agent-sync.sh - name: Test pull request template check run: PYTHONPATH=scripts python3 -m unittest discover -s tests/pr_template + - name: Test native audit JSON decoding + run: python3 -m unittest discover -s tests/audit - name: Test semantic registry generator and coverage report run: | python3 -m unittest discover -s tests/semantics_generator diff --git a/CHANGELOG.md b/CHANGELOG.md index 581cbf3..1f6e770 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -189,6 +189,7 @@ remains unsupported. native DBT. ### Fixed +- Fixed the native dependency audit reading Cargo JSON in the process locale encoding, so UTF-8 paths and diagnostics are accepted under an ASCII locale (#363). - Made the static probe and the binder share one bounded import parser, after the truncated-name fix for #270. Truncated, unterminated, empty or non-ASCII names, reserved bits and endless tables are reported by the probe and refused by the binder. - Fixed import binding writing some slots before finding an unresolved import, and service calls taking effect before an unreadable return address was noticed. A service that changes a nonvolatile register, including XMM6 to XMM15, now stops the guest (part of #201). - Fixed older import-generator templates that reported success for unimplemented wrappers, used a nonexistent exit reason, and read floating-point arguments from integer registers. diff --git a/scripts/audit/native.sh b/scripts/audit/native.sh index f039dc9..b9ae807 100755 --- a/scripts/audit/native.sh +++ b/scripts/audit/native.sh @@ -20,7 +20,7 @@ import subprocess executables = set() for filename in ("native-build.jsonl", "native-tests.jsonl"): - for line in (Path("artifacts") / filename).read_text().splitlines(): + for line in (Path("artifacts") / filename).read_text(encoding="utf-8").splitlines(): entry = json.loads(line) if entry.get("executable"): executables.add(entry["executable"]) diff --git a/tests/audit/test_native_json.py b/tests/audit/test_native_json.py new file mode 100644 index 0000000..17f7926 --- /dev/null +++ b/tests/audit/test_native_json.py @@ -0,0 +1,85 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +"""Exercise the native audit's Cargo JSON reader under an ASCII locale.""" + +import json +import os +from pathlib import Path +import subprocess +import sys +import tempfile +import unittest + + +ROOT = Path(__file__).resolve().parents[2] +SCRIPT = (ROOT / "scripts/audit/native.sh").read_text(encoding="utf-8") +# Run the actual reader, stopping before the native executable inspection. +READER = SCRIPT.split("python3 - <<'PY'\n", 1)[1].split( + "\nif not executables:", 1 +)[0] + + +class NativeJsonTests(unittest.TestCase): + def run_reader(self, streams): + with tempfile.TemporaryDirectory() as directory: + artifacts = Path(directory) / "artifacts" + artifacts.mkdir() + for name, payload in zip( + ("native-build.jsonl", "native-tests.jsonl"), streams, strict=True + ): + (artifacts / name).write_bytes(payload) + return subprocess.run( + [ + sys.executable, + "-c", + "import locale\n" + "assert locale.getencoding().lower() in ('ascii', 'us-ascii')\n" + + READER + + "\nprint(json.dumps(sorted(executables)))\n", + ], + cwd=directory, + env={ + **os.environ, + "LC_ALL": "C", + "PYTHONCOERCECLOCALE": "0", + "PYTHONUTF8": "0", + }, + capture_output=True, + encoding="utf-8", + check=False, + ) + + def test_utf8_in_each_cargo_stream(self): + for stream in (0, 1): + with self.subTest(stream=stream): + entry = { + "executable": "/synthetic/caf\u00e9/bin", + "filenames": ["/synthetic/caf\u00e9/lib.dylib"], + "message": {"rendered": "synthetic diagnostic: \u03bb"}, + } + streams = [b'{}\n', b'{}\n'] + streams[stream] = (json.dumps(entry, ensure_ascii=False) + "\n").encode( + "utf-8" + ) + result = self.run_reader(streams) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual( + json.loads(result.stdout), + ["/synthetic/caf\u00e9/bin", "/synthetic/caf\u00e9/lib.dylib"], + ) + + def test_ascii_streams_keep_deduplicated_artifacts(self): + entry = b'{"executable":"/synthetic/bin","filenames":["/synthetic/lib.so","/synthetic/lib.rlib"]}\n' + result = self.run_reader([entry, entry]) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual( + json.loads(result.stdout), ["/synthetic/bin", "/synthetic/lib.so"] + ) + + def test_invalid_utf8_is_rejected(self): + result = self.run_reader([b'{"executable":"\xff"}\n', b'{}\n']) + self.assertNotEqual(result.returncode, 0) + self.assertIn("UnicodeDecodeError", result.stderr) + + +if __name__ == "__main__": + unittest.main()