Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/v8/v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,10 @@ uint64_t V8::getMemorySize() { return memory_->data_size(); }

std::optional<std::string_view> V8::getMemory(uint64_t pointer, uint64_t size) {
assert(memory_ != nullptr);
// Make sure we're operating in a wasm32 memory space.
if (pointer > UINT32_MAX || size > UINT32_MAX || pointer + size > UINT32_MAX) {
return std::nullopt;
}
if (pointer + size > memory_->data_size()) {
return std::nullopt;
}
Expand All @@ -477,6 +481,10 @@ std::optional<std::string_view> V8::getMemory(uint64_t pointer, uint64_t size) {

bool V8::setMemory(uint64_t pointer, uint64_t size, const void *data) {
assert(memory_ != nullptr);
// Make sure we're operating in a wasm32 memory space.
if (pointer > UINT32_MAX || size > UINT32_MAX || pointer + size > UINT32_MAX) {
return false;
}
if (pointer + size > memory_->data_size()) {
return false;
}
Expand All @@ -486,6 +494,10 @@ bool V8::setMemory(uint64_t pointer, uint64_t size, const void *data) {

bool V8::getWord(uint64_t pointer, Word *word) {
constexpr auto size = sizeof(uint32_t);
// Make sure we're operating in a wasm32 memory space.
if (pointer > UINT32_MAX || pointer + size > UINT32_MAX) {
return false;
}
if (pointer + size > memory_->data_size()) {
return false;
}
Expand All @@ -497,6 +509,10 @@ bool V8::getWord(uint64_t pointer, Word *word) {

bool V8::setWord(uint64_t pointer, Word word) {
constexpr auto size = sizeof(uint32_t);
// Make sure we're operating in a wasm32 memory space.
if (pointer > UINT32_MAX || pointer + size > UINT32_MAX) {
return false;
}
if (pointer + size > memory_->data_size()) {
return false;
}
Expand Down