Skip to content

Commit d3d41e9

Browse files
committed
fix(domain_fronter): prevent panic when brace positions are inverted in fallback JSON extraction
In three error-path fallback sites (finalize_tunnel_response, finalize_batch_response, parse_relay_json), the code uses text.find('{') and text.rfind('}') to extract a JSON object from a messy response. When the response body is binary garbage, those byte values can appear in any order, causing start > end. The subsequent &text[start..=end] slice then panics with 'begin > end' and a SIGILL core dump. Add a bounds check at all three sites: if start > end, return a structured BadResponse error instead of slicing. Reproducible whenever Apps Script returns a non-JSON binary response body.
1 parent c7472aa commit d3d41e9

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

src/domain_fronter.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3037,6 +3037,12 @@ impl DomainFronter {
30373037
let end = text.rfind('}').ok_or_else(|| {
30383038
FronterError::BadResponse("no json end in tunnel response".into())
30393039
})?;
3040+
if start > end {
3041+
return Err(FronterError::BadResponse(format!(
3042+
"no valid json object in: {}",
3043+
&text.chars().take(200).collect::<String>()
3044+
)));
3045+
}
30403046
&text[start..=end]
30413047
};
30423048
Ok(serde_json::from_str(json_str)?)
@@ -3205,6 +3211,12 @@ impl DomainFronter {
32053211
let end = text.rfind('}').ok_or_else(|| {
32063212
FronterError::BadResponse("no json end in batch response".into())
32073213
})?;
3214+
if start > end {
3215+
return Err(FronterError::BadResponse(format!(
3216+
"no valid json object in: {}",
3217+
&text.chars().take(200).collect::<String>()
3218+
)));
3219+
}
32083220
&text[start..=end]
32093221
};
32103222
// Don't log payload content. Batch responses carry base64-encoded
@@ -4574,6 +4586,12 @@ fn parse_relay_json(body: &[u8]) -> Result<Vec<u8>, FronterError> {
45744586
&text[..text.len().min(200)]
45754587
))
45764588
})?;
4589+
if start > end {
4590+
return Err(FronterError::BadResponse(format!(
4591+
"no valid json object in: {}",
4592+
&text.chars().take(200).collect::<String>()
4593+
)));
4594+
}
45774595
serde_json::from_str(&text[start..=end])?
45784596
}
45794597
}

0 commit comments

Comments
 (0)