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

Issue 1420663003: Avoid calling %AddElement with a number out of array index range (Closed)

Created:
5 years, 1 month ago by Dan Ehrenberg
Modified:
5 years, 1 month ago
CC:
v8-reviews_googlegroups.com
Base URL:
https://chromium.googlesource.com/v8/v8.git@master
Target Ref:
refs/pending/heads/master
Project:
v8
Visibility:
Public.

Description

Avoid calling %AddElement with a number out of array index range This patch wraps callsites to %AddElement to fall back to adding a named property in case it is given an argument of 2**32 or greater. The change is needed because %AddElement is called by Array functions in various places, and ES2015 changes these Array functions to use ToLength rather than ToUint32, so several callsites of %AddElement which used to be reliable array indices may be larger numbers. While the proper long-term solution may be to call out to Object.defineProperty, this fix should allow the ToLength semantics to be shipped while preserving correctness and not requiring a rewrite. BUG=v8:4516 LOG=Y R=adamk TEST=Interactively ran Array.prototype.slice on an Array-like which exceeded array bounds, and found that this did not check-fail at runtime as it did before. Microbenchmarked this technique against the previous version on a simple reverse implementation and found at most a 1% slowdown, as opposed to other techniques, like calling %DefineDataPropertyUnchecked, which had a 20% slowdown or Object.defineProperty with a 80% slowdown. Committed: https://crrev.com/700bbdc673c9b023a7e9339f8f1a68dbe6b8a74d Cr-Commit-Position: refs/heads/master@{#31640}

Patch Set 1 #

Patch Set 2 : Fix Array.from and friends #

Total comments: 11

Patch Set 3 : Improve style #

Total comments: 1

Patch Set 4 : Fix naming #

Total comments: 1
Unified diffs Side-by-side diffs Delta from patch set Stats (+25 lines, -7 lines) Patch
M src/js/array.js View 1 2 3 5 chunks +7 lines, -5 lines 0 comments Download
M src/js/harmony-array.js View 1 2 3 3 chunks +3 lines, -1 line 0 comments Download
M src/js/runtime.js View 1 2 3 3 chunks +15 lines, -1 line 1 comment Download

Messages

Total messages: 40 (12 generated)
commit-bot: I haz the power
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1420663003/1 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1420663003/1
5 years, 1 month ago (2015-10-27 20:29:22 UTC) #2
commit-bot: I haz the power
Dry run: Try jobs failed on following builders: v8_mac_rel on tryserver.v8 (JOB_FAILED, http://build.chromium.org/p/tryserver.v8/builders/v8_mac_rel/builds/11201)
5 years, 1 month ago (2015-10-27 20:38:28 UTC) #6
commit-bot: I haz the power
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1420663003/20001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1420663003/20001
5 years, 1 month ago (2015-10-27 20:48:58 UTC) #8
Dan Ehrenberg
5 years, 1 month ago (2015-10-27 21:04:17 UTC) #9
commit-bot: I haz the power
Dry run: This issue passed the CQ dry run.
5 years, 1 month ago (2015-10-27 21:11:41 UTC) #11
adamk
Tried to think of a way to test this code in a reasonable amount of ...
5 years, 1 month ago (2015-10-27 22:03:07 UTC) #12
commit-bot: I haz the power
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1420663003/40001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1420663003/40001
5 years, 1 month ago (2015-10-27 22:09:42 UTC) #14
commit-bot: I haz the power
Dry run: This issue passed the CQ dry run.
5 years, 1 month ago (2015-10-27 22:27:43 UTC) #16
Dan Ehrenberg
PTAL https://codereview.chromium.org/1420663003/diff/20001/src/js/harmony-array.js File src/js/harmony-array.js (right): https://codereview.chromium.org/1420663003/diff/20001/src/js/harmony-array.js#newcode185 src/js/harmony-array.js:185: function AddArrayElement(constructor, array, i, value) { On 2015/10/27 ...
5 years, 1 month ago (2015-10-28 18:44:43 UTC) #17
adamk
https://codereview.chromium.org/1420663003/diff/20001/src/js/harmony-array.js File src/js/harmony-array.js (right): https://codereview.chromium.org/1420663003/diff/20001/src/js/harmony-array.js#newcode185 src/js/harmony-array.js:185: function AddArrayElement(constructor, array, i, value) { On 2015/10/28 18:44:43, ...
5 years, 1 month ago (2015-10-28 19:52:50 UTC) #18
adamk
lgtm to land once naming is fixed https://codereview.chromium.org/1420663003/diff/20001/src/js/harmony-array.js File src/js/harmony-array.js (right): https://codereview.chromium.org/1420663003/diff/20001/src/js/harmony-array.js#newcode185 src/js/harmony-array.js:185: function AddArrayElement(constructor, ...
5 years, 1 month ago (2015-10-28 20:03:07 UTC) #19
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1420663003/60001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1420663003/60001
5 years, 1 month ago (2015-10-28 20:08:24 UTC) #22
commit-bot: I haz the power
Committed patchset #4 (id:60001)
5 years, 1 month ago (2015-10-28 20:36:51 UTC) #23
commit-bot: I haz the power
Patchset 4 (id:??) landed as https://crrev.com/700bbdc673c9b023a7e9339f8f1a68dbe6b8a74d Cr-Commit-Position: refs/heads/master@{#31640}
5 years, 1 month ago (2015-10-28 20:37:24 UTC) #24
Benedikt Meurer
How about changing that to a runtime entry %AddIndexedProperty, because you end up in the ...
5 years, 1 month ago (2015-10-29 04:46:10 UTC) #26
Dan Ehrenberg
On 2015/10/29 at 04:46:10, bmeurer wrote: > How about changing that to a runtime entry ...
5 years, 1 month ago (2015-10-29 05:17:44 UTC) #27
Benedikt Meurer
On 2015/10/29 05:17:44, Dan Ehrenberg wrote: > On 2015/10/29 at 04:46:10, bmeurer wrote: > > ...
5 years, 1 month ago (2015-10-29 05:20:04 UTC) #28
Dan Ehrenberg
On 2015/10/29 at 05:20:04, bmeurer wrote: > On 2015/10/29 05:17:44, Dan Ehrenberg wrote: > > ...
5 years, 1 month ago (2015-10-29 05:27:33 UTC) #29
Benedikt Meurer
On 2015/10/29 05:27:33, Dan Ehrenberg wrote: > On 2015/10/29 at 05:20:04, bmeurer wrote: > > ...
5 years, 1 month ago (2015-10-29 05:30:15 UTC) #30
Dan Ehrenberg
On 2015/10/29 at 05:30:15, bmeurer wrote: > On 2015/10/29 05:27:33, Dan Ehrenberg wrote: > > ...
5 years, 1 month ago (2015-10-29 06:17:35 UTC) #31
Benedikt Meurer
On 2015/10/29 06:17:35, Dan Ehrenberg wrote: > On 2015/10/29 at 05:30:15, bmeurer wrote: > > ...
5 years, 1 month ago (2015-10-29 06:18:45 UTC) #32
Toon Verwaest
My opinion is indeed that we should separate AddElement (adding only elements) from AddNamedProperty (adding ...
5 years, 1 month ago (2015-10-29 10:41:01 UTC) #34
Toon Verwaest
(And if we have those 2 already, adding yet another runtime function just do mimick ...
5 years, 1 month ago (2015-10-29 10:41:44 UTC) #35
Toon Verwaest
For that matter, how can slice create an array with elements that are out of ...
5 years, 1 month ago (2015-10-29 10:56:18 UTC) #36
Toon Verwaest
(Ok I see, Array-like... ignore my last comment :))
5 years, 1 month ago (2015-10-29 11:06:56 UTC) #37
Jakob Kummerow
DBC: before anyone starts adding new runtime functions, let me point out that Runtime_SetProperty (which ...
5 years, 1 month ago (2015-10-29 12:07:21 UTC) #38
adamk
On 2015/10/29 12:07:21, Jakob wrote: > DBC: before anyone starts adding new runtime functions, let ...
5 years, 1 month ago (2015-10-29 14:29:01 UTC) #39
Dan Ehrenberg
5 years, 1 month ago (2015-10-29 18:15:41 UTC) #40
Message was sent while issue was closed.
On 2015/10/29 at 10:41:01, verwaest wrote:
> My opinion is indeed that we should separate AddElement (adding only elements)
from AddNamedProperty (adding only named properties) so the runtime has a clear
idea of what you are doing. Sure, right now it could be that all such calls
would have to go through this helper; but shouldn't we know exactly which ranges
of properties end up where? Shouldn't we rather have 2 loops, one which adds
elements until the end of the valid element range, and one which adds named
properties for the rest?

Toon, doing the conditional each time turned out to be really cheap in my
microbenchmark. I don't think it'd be a worthwhile optimization to change this
into two loops.
> 
> https://codereview.chromium.org/1420663003/diff/60001/src/js/runtime.js
> File src/js/runtime.js (right):
> 
>
https://codereview.chromium.org/1420663003/diff/60001/src/js/runtime.js#newco...
> src/js/runtime.js:213: if (index === TO_UINT32(index)) {
> kMaxUint32 isn't a valid element either. Max length of arrays is kMaxUint32,
so max element is kMaxUint32-1.

Oh, oops. I wonder why this seemed to fix the 'illegal access' issue. I'll write
up a fix.

Powered by Google App Engine
This is Rietveld 408576698