Skip to content

Commit 1ef2165

Browse files
authored
WasmFS: Handle overflow in growing MemoryFile buffers (#20765)
Fixes #20741
1 parent 1c7c271 commit 1ef2165

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

system/lib/wasmfs/backends/memory_backend.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ namespace wasmfs {
1515

1616
ssize_t MemoryDataFile::write(const uint8_t* buf, size_t len, off_t offset) {
1717
if (offset + len > buffer.size()) {
18+
if (offset + len > buffer.max_size()) {
19+
// Overflow: the necessary size fits in an off_t, but cannot fit in the
20+
// container.
21+
return -EIO;
22+
}
1823
buffer.resize(offset + len);
1924
}
2025
std::memcpy(&buffer[offset], buf, len);

0 commit comments

Comments
 (0)