From a18cd3fff7d8fe1c81511c2da712165cc014be20 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 7 Jul 2026 12:37:21 +0000 Subject: [PATCH 1/2] Initial plan From 4ec214b40ef4089f036c59800b4302fd74f680ad Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 7 Jul 2026 12:41:33 +0000 Subject: [PATCH 2/2] Fix UB in IOChunk::as_str(): only cache utf8_verified on successful UTF-8 validation --- src/sed/fast_io.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/sed/fast_io.rs b/src/sed/fast_io.rs index e6017bd3..5fd33268 100644 --- a/src/sed/fast_io.rs +++ b/src/sed/fast_io.rs @@ -244,9 +244,13 @@ impl<'a> IOChunk<'a> { // Use cached result Ok(unsafe { self.content.as_str_unchecked() }) } else { - let result = str::from_utf8(content); - self.utf8_verified.set(true); - result.map_err(|e| USimpleError::new(2, e.to_string())) + match str::from_utf8(content) { + Ok(s) => { + self.utf8_verified.set(true); + Ok(s) + } + Err(e) => Err(USimpleError::new(2, e.to_string())), + } } } IOChunkContent::Owned { content, .. } => Ok(content),