diff --git a/soroban-env-common/src/symbol.rs b/soroban-env-common/src/symbol.rs index 07ab6d418..cb2d9e3a5 100644 --- a/soroban-env-common/src/symbol.rs +++ b/soroban-env-common/src/symbol.rs @@ -319,9 +319,17 @@ impl TryFromVal for SymbolStr { } else { let obj: SymbolObject = unsafe { SymbolObject::unchecked_from_val(v.0) }; let mut arr = [0u8; SCSYMBOL_LIMIT as usize]; - env.symbol_copy_to_slice(obj, Val::U32_ZERO, &mut arr) - .map_err(Into::into)?; - Ok(SymbolStr(arr)) + let len: u32 = env.symbol_len(obj).map_err(Into::into)?.into(); + if let Some(slice) = arr.get_mut(..len as usize) { + env.symbol_copy_to_slice(obj, Val::U32_ZERO, slice) + .map_err(Into::into)?; + Ok(SymbolStr(arr)) + } else { + Err(crate::Error::from_type_and_code( + crate::xdr::ScErrorType::Value, + crate::xdr::ScErrorCode::InternalError, + )) + } } } } diff --git a/soroban-env-host/src/host.rs b/soroban-env-host/src/host.rs index f6a9dafa8..cf185fcb7 100644 --- a/soroban-env-host/src/host.rs +++ b/soroban-env-host/src/host.rs @@ -1123,8 +1123,7 @@ impl EnvBase for Host { b_pos: U32Val, slice: &mut [u8], ) -> Result<(), HostError> { - let len = self.visit_obj(s, |sym: &ScSymbol| Ok(sym.len()))?; - self.memobj_copy_to_slice::(s, b_pos, &mut slice[..len]) + self.memobj_copy_to_slice::(s, b_pos, slice) } fn bytes_new_from_slice(&self, mem: &[u8]) -> Result {