Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(273)

Unified Diff: src/value-serializer.cc

Issue 2399873002: ValueSerializer: Add more checks before trying to allocate memory for a dense array. (Closed)
Patch Set: signed/unsigned Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/unittests/value-serializer-unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/value-serializer.cc
diff --git a/src/value-serializer.cc b/src/value-serializer.cc
index 69b958292e39085e0db735314b70dc6e8d90a6b4..b3052b67dc1c5769a58d0f7c54d7a18fa58a5436 100644
--- a/src/value-serializer.cc
+++ b/src/value-serializer.cc
@@ -470,6 +470,8 @@ Maybe<bool> ValueSerializer::WriteJSArray(Handle<JSArray> array) {
array->HasFastElements() && !array->HasFastHoleyElements();
if (should_serialize_densely) {
+ DCHECK_LE(length, static_cast<uint32_t>(FixedArray::kMaxLength));
+
// TODO(jbroman): Distinguish between undefined and a hole (this can happen
// if serializing one of the elements deletes another). This requires wire
// format changes.
@@ -1165,8 +1167,15 @@ MaybeHandle<JSArray> ValueDeserializer::ReadDenseJSArray() {
// If we are at the end of the stack, abort. This function may recurse.
STACK_CHECK(isolate_, MaybeHandle<JSArray>());
+ // We shouldn't permit an array larger than the biggest we can request from
+ // V8. As an additional sanity check, since each entry will take at least one
+ // byte to encode, if there are fewer bytes than that we can also fail fast.
uint32_t length;
- if (!ReadVarint<uint32_t>().To(&length)) return MaybeHandle<JSArray>();
+ if (!ReadVarint<uint32_t>().To(&length) ||
+ length > static_cast<uint32_t>(FixedArray::kMaxLength) ||
+ length > static_cast<size_t>(end_ - position_)) {
+ return MaybeHandle<JSArray>();
+ }
uint32_t id = next_id_++;
HandleScope scope(isolate_);
« no previous file with comments | « no previous file | test/unittests/value-serializer-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698