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

Unified Diff: src/js/array.js

Issue 1428483002: Check that array length stays a safe integer in Array.prototype.push (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix test and improve comments Created 5 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 | src/messages.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/js/array.js
diff --git a/src/js/array.js b/src/js/array.js
index b13e4e239223093af848f17b0b61d4a02390e371..d84635653cd0b34f9585ee5c2546b26a8be6a52b 100644
--- a/src/js/array.js
+++ b/src/js/array.js
@@ -517,6 +517,15 @@ function ArrayPush() {
var n = TO_LENGTH_OR_UINT32(array.length);
var m = %_ArgumentsLength();
+ // It appears that there is no enforced, absolute limit on the number of
+ // arguments, but it would be very slow for users to use 2**32 or more.
+ // To avoid integer overflow, do the comparison to the max safe integer
+ // after subtracting 2**32 from both sides. To stay on the safe side, also
+ // prohibit this function from being called with more than 2**32 arguments.
+ if (m > 1 << 32 || (n - (1 << 32)) + m > kMaxSafeInteger - (1 << 32)) {
adamk 2015/10/26 23:14:28 "1 << 32" isn't doing what you want. It returns 1.
Dan Ehrenberg 2015/10/27 00:47:36 Right. I finally settled on something that works,
+ throw MakeTypeError(kPushPastSafeLength, m, n);
+ }
+
for (var i = 0; i < m; i++) {
array[i+n] = %_Arguments(i);
}
« no previous file with comments | « no previous file | src/messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698