@@ -469,6 +469,10 @@ uint64_t V8::getMemorySize() { return memory_->data_size(); }
469
469
470
470
std::optional<std::string_view> V8::getMemory (uint64_t pointer, uint64_t size) {
471
471
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
+ }
472
476
if (pointer + size > memory_->data_size ()) {
473
477
return std::nullopt;
474
478
}
@@ -477,6 +481,10 @@ std::optional<std::string_view> V8::getMemory(uint64_t pointer, uint64_t size) {
477
481
478
482
bool V8::setMemory (uint64_t pointer, uint64_t size, const void *data) {
479
483
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
+ }
480
488
if (pointer + size > memory_->data_size ()) {
481
489
return false ;
482
490
}
@@ -486,6 +494,10 @@ bool V8::setMemory(uint64_t pointer, uint64_t size, const void *data) {
486
494
487
495
bool V8::getWord (uint64_t pointer, Word *word) {
488
496
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
+ }
489
501
if (pointer + size > memory_->data_size ()) {
490
502
return false ;
491
503
}
@@ -497,6 +509,10 @@ bool V8::getWord(uint64_t pointer, Word *word) {
497
509
498
510
bool V8::setWord (uint64_t pointer, Word word) {
499
511
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
+ }
500
516
if (pointer + size > memory_->data_size ()) {
501
517
return false ;
502
518
}
0 commit comments