From a580a5d5e14afb8c019088d0a2ca220e29dd638d Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Tue, 31 Jul 2018 15:19:36 +0800 Subject: [PATCH 1/2] Improve return data truncate logic --- ethcore/evm/src/interpreter/memory.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ethcore/evm/src/interpreter/memory.rs b/ethcore/evm/src/interpreter/memory.rs index 843aeef3b57..43f68d40e04 100644 --- a/ethcore/evm/src/interpreter/memory.rs +++ b/ethcore/evm/src/interpreter/memory.rs @@ -119,14 +119,19 @@ impl Memory for Vec { fn into_return_data(mut self, offset: U256, size: U256) -> ReturnData { let mut offset = offset.low_u64() as usize; let size = size.low_u64() as usize; + if !is_valid_range(offset, size) { - return ReturnData::empty() + return ReturnData::empty(); } + if self.len() - size > MAX_RETURN_WASTE_BYTES { - { let _ = self.drain(..offset); } - self.truncate(size); - self.shrink_to_fit(); - offset = 0; + if offset == 0 { + self.truncate(size); + self.shrink_to_fit(); + } else { + self = self[offset..size].to_vec(); + offset = 0; + } } ReturnData::new(self, offset, size) } From a3e57723c38cd2cb18d0438524c47dd201182dcb Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Tue, 31 Jul 2018 17:03:41 +0800 Subject: [PATCH 2/2] fix: size -> offset + size --- ethcore/evm/src/interpreter/memory.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethcore/evm/src/interpreter/memory.rs b/ethcore/evm/src/interpreter/memory.rs index 43f68d40e04..313d1b48fba 100644 --- a/ethcore/evm/src/interpreter/memory.rs +++ b/ethcore/evm/src/interpreter/memory.rs @@ -129,7 +129,7 @@ impl Memory for Vec { self.truncate(size); self.shrink_to_fit(); } else { - self = self[offset..size].to_vec(); + self = self[offset..(offset + size)].to_vec(); offset = 0; } }