Attackathon _ Fuel Network 33433 - [Smart Contract - Low] Self-append in Bytes data structure causes
Description
Brief/Intro
Vulnerability Details
pub fn append(ref mut self, ref mut other: self) {
let other_len = other.len(); //@audit no check if other != self
if other_len == 0 {
return
};
// optimization for when starting with empty bytes and appending to it
if self.len == 0 {
self = other;
other.clear();
return;
};
let both_len = self.len + other_len;
let other_start = self.len;
// reallocate with combined capacity, write `other`, set buffer capacity
if self.buf.capacity() < both_len {
let new_slice = raw_slice::from_parts::<u8>(
realloc_bytes(self.buf.ptr(), self.buf.capacity(), both_len),
both_len,
);
self.buf = RawBytes::from(new_slice);
}
let new_ptr = self.buf.ptr().add_uint_offset(other_start);
other.ptr().copy_bytes_to(new_ptr, other_len);
// set capacity and length
self.len = both_len;
// clear `other`
other.clear(); //@audit clears all the elements
}Impact Details
References
Recommendation
Proof of concept
Proof of Concept
PreviousAttackathon _ Fuel Network 33407 - [Smart Contract - Insight] Missing Zero-Check for to Address in wNextAttackathon _ Fuel Network 33444 - [Smart Contract - Insight] Sway compiler crash for access out-of-
Last updated
Was this helpful?