Skip to content

Commit 3c6482a

Browse files
committed
Fixed: Reject overflowing Content-Length in webfetch
Fail fast on 32-bit overflow in blocking and tokio paths.
1 parent 5c8d961 commit 3c6482a

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

src/llm-coding-tools-core/src/tools/webfetch/blocking_impl.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,17 @@ pub fn fetch_url(
3535
.to_string();
3636

3737
// Check Content-Length header if available for early rejection and preallocation
38-
let content_length = response.content_length().map(|len| len as usize);
38+
let content_length = response
39+
.content_length()
40+
.map(|len| {
41+
usize::try_from(len).map_err(|_| {
42+
ToolError::Http(format!(
43+
"Content-Length {} exceeds platform limits for {}",
44+
len, url
45+
))
46+
})
47+
})
48+
.transpose()?;
3949
if let Some(len) = content_length {
4050
check_size(len, url)?;
4151
}

src/llm-coding-tools-core/src/tools/webfetch/tokio_impl.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,15 @@ pub async fn fetch_url(
3636
// Check Content-Length header if available for early rejection and preallocation
3737
let content_length = response
3838
.content_length()
39-
.and_then(|len| usize::try_from(len).ok());
39+
.map(|len| {
40+
usize::try_from(len).map_err(|_| {
41+
ToolError::Http(format!(
42+
"Content-Length {} exceeds platform limits for {}",
43+
len, url
44+
))
45+
})
46+
})
47+
.transpose()?;
4048
if let Some(len) = content_length {
4149
check_size(len, url)?;
4250
}

0 commit comments

Comments
 (0)