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

Unified Diff: src/builtins.cc

Issue 1863553003: [elements] Fix length bounds precheck for Array.prototype.concat (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: adding test Created 4 years, 8 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 | src/elements.cc » ('j') | src/elements.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins.cc
diff --git a/src/builtins.cc b/src/builtins.cc
index 347b428d5c250d00d8d3f3f096fdb84d42926536..d3c27dba387e3accb1dc2b1c68514dc65de7304b 100644
--- a/src/builtins.cc
+++ b/src/builtins.cc
@@ -1528,6 +1528,12 @@ Object* Slow_ArrayConcat(Arguments* args, Handle<Object> species,
MaybeHandle<JSArray> Fast_ArrayConcat(Isolate* isolate, Arguments* args) {
+ // We shouldn't overflow when adding another len.
+ const int kHalfOfMaxInt = 1 << (kBitsPerInt - 2);
+ STATIC_ASSERT(FixedArray::kMaxLength < kHalfOfMaxInt);
+ STATIC_ASSERT(FixedDoubleArray::kMaxLength < kHalfOfMaxInt);
+ USE(kHalfOfMaxInt);
+
int n_arguments = args->length();
int result_len = 0;
{
@@ -1547,16 +1553,13 @@ MaybeHandle<JSArray> Fast_ArrayConcat(Isolate* isolate, Arguments* args) {
if (HasConcatSpreadableModifier(isolate, array)) {
return MaybeHandle<JSArray>();
}
- int len = Smi::cast(array->length())->value();
-
- // We shouldn't overflow when adding another len.
- const int kHalfOfMaxInt = 1 << (kBitsPerInt - 2);
- STATIC_ASSERT(FixedArray::kMaxLength < kHalfOfMaxInt);
- USE(kHalfOfMaxInt);
- result_len += len;
+ // The Array length is guaranted to be <= kHalfOfMaxInt thus we won't
+ // overflow.
+ result_len += Smi::cast(array->length())->value();
DCHECK(result_len >= 0);
// Throw an Error if we overflow the FixedArray limits
- if (FixedArray::kMaxLength < result_len) {
+ if (FixedDoubleArray::kMaxLength < result_len) {
Igor Sheludko 2016/04/05 12:53:27 How about also adding: STATIC_ASSERT(FixedDouble
Camillo Bruni 2016/04/05 15:07:48 done.
+ AllowHeapAllocation allow_gc;
THROW_NEW_ERROR(isolate,
NewRangeError(MessageTemplate::kInvalidArrayLength),
JSArray);
« no previous file with comments | « no previous file | src/elements.cc » ('j') | src/elements.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698