Skip to content

Commit 23464f3

Browse files
committed
fix(domain_fronter): fix panic from non-char-boundary slice in error paths
Four error format strings truncated a &str at byte offset 200 using &text[..text.len().min(200)]. When the response body contains multi-byte UTF-8 characters (quota error HTML, brotli-compressed or binary Apps Script responses, cold-start warning pages), byte offset 200 can fall inside a character boundary, causing a panic and SIGILL core dump. Replace byte-offset truncation with char-aware truncation via .chars().take(200).collect::<String>() at all four sites: - parse_relay_json: "no json in" and "no json end in" messages - finalize_tunnel_response: "no json in tunnel response" message - finalize_batch_response: "no json in batch response" message Reproducible under normal operating conditions when Apps Script returns a non-JSON body under quota pressure or transient errors.
1 parent b4d0f73 commit 23464f3

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/domain_fronter.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3037,7 +3037,7 @@ impl DomainFronter {
30373037
let start = text.find('{').ok_or_else(|| {
30383038
FronterError::BadResponse(format!(
30393039
"no json in tunnel response: {}",
3040-
&text[..text.len().min(200)]
3040+
&text.chars().take(200).collect::<String>()
30413041
))
30423042
})?;
30433043
let end = text.rfind('}').ok_or_else(|| {
@@ -3205,7 +3205,7 @@ impl DomainFronter {
32053205
let start = text.find('{').ok_or_else(|| {
32063206
FronterError::BadResponse(format!(
32073207
"no json in batch response: {}",
3208-
&text[..text.len().min(200)]
3208+
&text.chars().take(200).collect::<String>()
32093209
))
32103210
})?;
32113211
let end = text.rfind('}').ok_or_else(|| {
@@ -4578,13 +4578,13 @@ fn parse_relay_json(body: &[u8]) -> Result<Vec<u8>, FronterError> {
45784578
let start = text.find('{').ok_or_else(|| {
45794579
FronterError::BadResponse(format!(
45804580
"no json in: {}",
4581-
&text[..text.len().min(200)]
4581+
&text.chars().take(200).collect::<String>()
45824582
))
45834583
})?;
45844584
let end = text.rfind('}').ok_or_else(|| {
45854585
FronterError::BadResponse(format!(
45864586
"no json end in: {}",
4587-
&text[..text.len().min(200)]
4587+
&text.chars().take(200).collect::<String>()
45884588
))
45894589
})?;
45904590
serde_json::from_str(&text[start..=end])?

0 commit comments

Comments
 (0)