From 5ef607e2afe7eaf7e2ccdf62f3ffacfede3c5fca Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 20 Jul 2026 17:10:49 +0900 Subject: fix(no-proxy-pattern): stop chr() corrupting IP bytes as lossy UTF-8 shirabe_php_shim::chr() returned a Rust String, which lossily re-encodes bytes >= 0x80 as UTF-8 replacement characters. ip_get_mask, ip_get_network, and ip_map_to_6 relied on chr() to build raw in_addr and netmask byte arrays, corrupting IPv4-in-IPv6 mappings and CIDR netmasks. Build the Vec byte arrays directly instead of round-tripping through String, and un-ignore test_ip_address and test_ip_range now that the underlying bug is fixed. chr()'s only other caller (http_downloader.rs, an ASCII ESC byte in a regex pattern) didn't need the indirection either, so remove the shim function entirely. Co-Authored-By: Claude Sonnet 5 --- crates/shirabe-php-shim/src/string.rs | 6 ------ 1 file changed, 6 deletions(-) (limited to 'crates/shirabe-php-shim/src/string.rs') diff --git a/crates/shirabe-php-shim/src/string.rs b/crates/shirabe-php-shim/src/string.rs index 97c66953..2617399f 100644 --- a/crates/shirabe-php-shim/src/string.rs +++ b/crates/shirabe-php-shim/src/string.rs @@ -1289,12 +1289,6 @@ pub fn ucfirst(s: &str) -> String { } } -pub fn chr(_value: u8) -> String { - // TODO(phase-d): PHP chr() yields a single raw byte; for values >= 0x80 that byte is not valid - // UTF-8, so storing it in a Rust String forces a lossy substitution. - String::from_utf8_lossy(&[_value]).into_owned() -} - // Port of PHP's addcslashes: every byte that falls in the (range-expanded) charlist is // backslash-escaped, with non-printable bytes rendered as the C escape or a three-digit octal. pub fn addcslashes(_string: &str, _charlist: &str) -> String { -- cgit v1.3.1