Skip to content

Commit 073b92a

Browse files
authored
Allow proxy_get_buffer_byts(0, MAX, ...). (#52)
This convention is already allowed in proxy_set_buffer_bytes(), and it was previously allowed for proxy_get_buffer_byts(). Signed-off-by: Piotr Sikora <[email protected]>
1 parent 4598dc3 commit 073b92a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/exports.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,10 +494,14 @@ Word get_buffer_bytes(void *raw_context, Word type, Word start, Word length, Wor
494494
if (!buffer) {
495495
return WasmResult::NotFound;
496496
}
497-
// check for overflow.
498-
if (buffer->size() < start + length || start > start + length) {
497+
// Check for overflow.
498+
if (start > start + length) {
499499
return WasmResult::BadArgument;
500500
}
501+
// Don't overread.
502+
if (start + length > buffer->size()) {
503+
length = buffer->size() - start;
504+
}
501505
if (length > 0) {
502506
return buffer->copyTo(context->wasm(), start, length, ptr_ptr, size_ptr);
503507
}

0 commit comments

Comments
 (0)