Skip to content

Commit efbbf16

Browse files
Copilotjacobjmc
andauthored
Guard base64 data URL image decoding against unbounded memory allocation (#10)
* Initial plan * Add pre/post-decode size guards for data URL base64 images Co-authored-by: jacobjmc <111402762+jacobjmc@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jacobjmc <111402762+jacobjmc@users.noreply.github.com>
1 parent 575a423 commit efbbf16

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src-tauri/src/shared/codex_core.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,9 +1129,16 @@ fn persist_data_image_to_temp_file(data_url: &str) -> Option<String> {
11291129
if !metadata.starts_with("image/") {
11301130
return None;
11311131
}
1132+
let estimated_len = encoded.len().saturating_mul(3) / 4;
1133+
if estimated_len > URL_IMAGE_MAX_BYTES {
1134+
return None;
1135+
}
11321136
let bytes = base64::engine::general_purpose::STANDARD
11331137
.decode(encoded)
11341138
.ok()?;
1139+
if bytes.len() > URL_IMAGE_MAX_BYTES {
1140+
return None;
1141+
}
11351142

11361143
let mut hasher = DefaultHasher::new();
11371144
metadata.hash(&mut hasher);

0 commit comments

Comments
 (0)