Skip to content

Commit 174c6be

Browse files
PiotrSikoraknm3000
authored andcommitted
v8: make sure we're operating in a wasm32 memory space. (#307)
Reported by Chris Ertl from Google Security. Signed-off-by: Piotr Sikora <[email protected]>
1 parent c5b39ec commit 174c6be

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/v8/v8.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,10 @@ uint64_t V8::getMemorySize() { return memory_->data_size(); }
469469

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

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

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

498510
bool V8::setWord(uint64_t pointer, Word word) {
499511
constexpr auto size = sizeof(uint32_t);
512+
// Make sure we're operating in a wasm32 memory space.
513+
if (pointer > UINT32_MAX || pointer + size > UINT32_MAX) {
514+
return false;
515+
}
500516
if (pointer + size > memory_->data_size()) {
501517
return false;
502518
}

0 commit comments

Comments
 (0)