@@ -469,6 +469,10 @@ uint64_t V8::getMemorySize() { return memory_->data_size(); }
469469
470470std::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
478482bool 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
487495bool 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
498510bool 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