21
21
22
22
#include < stdlib.h> // calloc, etc
23
23
#include < string.h> // memmove
24
+ #include < stdint.h>
24
25
25
26
#include " v8_typed_array.h"
26
27
#include " node_buffer.h"
@@ -722,11 +723,14 @@ class DataView {
722
723
// TODO(deanm): All of these things should be cacheable.
723
724
int element_size = SizeOfArrayElementForType (
724
725
args.This ()->GetIndexedPropertiesExternalArrayDataType ());
725
- int size = args.This ()->GetIndexedPropertiesExternalArrayDataLength () *
726
- element_size;
726
+ assert (element_size > 0 );
727
+ int size = args.This ()->GetIndexedPropertiesExternalArrayDataLength ();
728
+ assert (size >= 0 );
727
729
728
- if (index + sizeof (T) > (unsigned )size) // TODO(deanm): integer overflow.
730
+ if (static_cast <uint64_t >(index ) + sizeof (T) >
731
+ static_cast <uint64_t >(size) * element_size) {
729
732
return ThrowError (" Index out of range." );
733
+ }
730
734
731
735
void * ptr = args.This ()->GetIndexedPropertiesExternalArrayData ();
732
736
return cTypeToValue<T>(getValue<T>(ptr, index , !little_endian));
@@ -742,11 +746,14 @@ class DataView {
742
746
// TODO(deanm): All of these things should be cacheable.
743
747
int element_size = SizeOfArrayElementForType (
744
748
args.This ()->GetIndexedPropertiesExternalArrayDataType ());
745
- int size = args.This ()->GetIndexedPropertiesExternalArrayDataLength () *
746
- element_size;
749
+ assert (element_size > 0 );
750
+ int size = args.This ()->GetIndexedPropertiesExternalArrayDataLength ();
751
+ assert (size >= 0 );
747
752
748
- if (index + sizeof (T) > (unsigned )size) // TODO(deanm): integer overflow.
753
+ if (static_cast <uint64_t >(index ) + sizeof (T) >
754
+ static_cast <uint64_t >(size) * element_size) {
749
755
return ThrowError (" Index out of range." );
756
+ }
750
757
751
758
void * ptr = args.This ()->GetIndexedPropertiesExternalArrayData ();
752
759
setValue<T>(ptr, index , valueToCType<T>(args[1 ]), !little_endian);
0 commit comments