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

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: Error should be a TypeError, not a RangeError 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..d9ae35d4e8609d9ef513795f80d253682a91c227 100644
--- a/src/js/array.js
+++ b/src/js/array.js
@@ -517,6 +517,13 @@ function ArrayPush() {
var n = TO_LENGTH_OR_UINT32(array.length);
var m = %_ArgumentsLength();
+ // The length of arguments can never be more than 2 ** 32, so
adamk 2015/10/26 21:21:02 It looks to me like it can't be more than 2**16, a
Dan Ehrenberg 2015/10/26 22:59:31 We talked about this offline. Apparently it can be
+ // we can do the comparison after subtracting that much from
+ // the length in order to avoid integer overflow.
adamk 2015/10/26 21:21:03 Is this math necessary to get the right answer or
Dan Ehrenberg 2015/10/26 22:59:31 It's necessary for the answer. Without that change
+ if ((n - (1 << 32)) + m > kMaxSafeInteger - (1 << 32)) {
+ throw MakeTypeError(kPushPastSafeLength, m, n);
adamk 2015/10/26 21:21:02 Nit: indentation off, needs one more leading space
Dan Ehrenberg 2015/10/26 22:59:31 Fixed
+ }
+
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