mirror of
https://github.com/MacosPorters/betterxen.git
synced 2026-11-26 03:39:52 +00:00
Preserve UTF-8 native inspection output
Signed-off-by: Arths17 <Atharvranjan8@gmail.com>
This commit is contained in:
1 parent
281d92bfb5
commit
00eb6971e9
3 files changed
+43
-13
No files matched your search
+1
-1
@@ -189,7 +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).
|
||||
- Fixed the native dependency audit reading Cargo JSON and inspection-tool output in the process locale encoding; it now reads and reports UTF-8 paths and diagnostics 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.
|
||||
|
||||
@@ -17,6 +17,9 @@ python3 - <<'PY'
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
sys.stdout.reconfigure(encoding="utf-8")
|
||||
|
||||
executables = set()
|
||||
for filename in ("native-build.jsonl", "native-tests.jsonl"):
|
||||
@@ -32,11 +35,11 @@ if not executables:
|
||||
raise SystemExit("No Cargo executable or loadable dependency artifacts found.")
|
||||
for path in sorted(executables):
|
||||
subprocess.run(["file", path], check=True)
|
||||
archs = subprocess.check_output(["lipo", "-archs", path], text=True).strip()
|
||||
archs = subprocess.check_output(["lipo", "-archs", path], encoding="utf-8").strip()
|
||||
print(archs, flush=True)
|
||||
if archs != "arm64":
|
||||
raise SystemExit(f"Non-ARM64 build artifact: {path}")
|
||||
linkage = subprocess.check_output(["otool", "-L", path], text=True)
|
||||
linkage = subprocess.check_output(["otool", "-L", path], encoding="utf-8")
|
||||
print(linkage, end="", flush=True)
|
||||
if any(name in linkage.casefold() for name in ("vulkan", "moltenvk")):
|
||||
raise SystemExit(f"Unexpected graphics linkage: {path}")
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""Exercise the native audit's Cargo JSON reader under an ASCII locale."""
|
||||
"""Exercise native audit JSON decoding and inspection under an ASCII locale."""
|
||||
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import platform
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
@@ -12,14 +13,13 @@ 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]
|
||||
AUDIT = SCRIPT.split("python3 - <<'PY'\n", 1)[1].rsplit("\nPY", 1)[0]
|
||||
# Reader-only cases stop before the native executable inspection.
|
||||
READER = AUDIT.split("\nif not executables:", 1)[0]
|
||||
|
||||
|
||||
class NativeJsonTests(unittest.TestCase):
|
||||
def run_reader(self, streams):
|
||||
def run_audit(self, streams, code=READER):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
artifacts = Path(directory) / "artifacts"
|
||||
artifacts.mkdir()
|
||||
@@ -33,7 +33,7 @@ class NativeJsonTests(unittest.TestCase):
|
||||
"-c",
|
||||
"import locale\n"
|
||||
"assert locale.getencoding().lower() in ('ascii', 'us-ascii')\n"
|
||||
+ READER
|
||||
+ code
|
||||
+ "\nprint(json.dumps(sorted(executables)))\n",
|
||||
],
|
||||
cwd=directory,
|
||||
@@ -60,7 +60,7 @@ class NativeJsonTests(unittest.TestCase):
|
||||
streams[stream] = (json.dumps(entry, ensure_ascii=False) + "\n").encode(
|
||||
"utf-8"
|
||||
)
|
||||
result = self.run_reader(streams)
|
||||
result = self.run_audit(streams)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertEqual(
|
||||
json.loads(result.stdout),
|
||||
@@ -69,17 +69,44 @@ class NativeJsonTests(unittest.TestCase):
|
||||
|
||||
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])
|
||||
result = self.run_audit([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'])
|
||||
result = self.run_audit([b'{"executable":"\xff"}\n', b'{}\n'])
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertIn("UnicodeDecodeError", result.stderr)
|
||||
|
||||
@unittest.skipUnless(
|
||||
sys.platform == "darwin" and platform.machine() == "arm64",
|
||||
"requires native ARM64 macOS inspection tools",
|
||||
)
|
||||
def test_native_inspection_of_unicode_path_under_ascii_locale(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
source = root / "fixture.c"
|
||||
source.write_text("int main(void) { return 0; }\n", encoding="utf-8")
|
||||
binary = root / "caf\u00e9"
|
||||
subprocess.run(
|
||||
["/usr/bin/clang", "-arch", "arm64", str(source), "-o", str(binary)],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
)
|
||||
entry = (
|
||||
json.dumps({"executable": str(binary)}, ensure_ascii=False) + "\n"
|
||||
).encode("utf-8")
|
||||
for stream in (0, 1):
|
||||
with self.subTest(stream=stream):
|
||||
streams = [b'{}\n', b'{}\n']
|
||||
streams[stream] = entry
|
||||
result = self.run_audit(streams, code=AUDIT)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertIn(str(binary), result.stdout)
|
||||
self.assertIn("Checked 1 native executables", result.stdout)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user