WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
153908
Arrayify for a typed array shouldn't create a monster
https://bugs.webkit.org/show_bug.cgi?id=153908
Summary
Arrayify for a typed array shouldn't create a monster
Filip Pizlo
Reported
2016-02-04 20:59:53 PST
Arrayify over a typed array will repurpose the indexing header for something different than what typed arrays expect, leading to an object that's in a bizarre state.
Attachments
the patch
(10.93 KB, patch)
2016-02-04 21:02 PST
,
Filip Pizlo
mark.lam
: review+
Details
Formatted Diff
Diff
View All
Add attachment
proposed patch, testcase, etc.
Filip Pizlo
Comment 1
2016-02-04 21:02:09 PST
Created
attachment 270724
[details]
the patch
Mark Lam
Comment 2
2016-02-05 10:03:55 PST
Comment on
attachment 270724
[details]
the patch View in context:
https://bugs.webkit.org/attachment.cgi?id=270724&action=review
> Source/JavaScriptCore/runtime/JSObject.cpp:597 > - // this case if we ever cared. > - enterDictionaryIndexingModeWhenArrayStorageAlreadyExists(vm, ensureArrayStorageSlow(vm)); > + // this case if we ever cared. Note that ensureArrayStorage() can return null if the object > + // doesn't support traditional indexed properties. At the time of writing, this just affects > + // typed arrays. > + if (ArrayStorage* storage = ensureArrayStorageSlow(vm)) > + enterDictionaryIndexingModeWhenArrayStorageAlreadyExists(vm, storage);
JSObject::enterDictionaryIndexingMode() seems to be called from JSArray::setLengthWritable() and JSObject::preventExtensions() with the assumption that it will succeed in entering indexing mode. Can you please explain why it is ok to simply do nothing is we fail to ensureArrayStorageSlow()?
> Source/JavaScriptCore/runtime/JSObject.cpp:2548 > - > - return Butterfly::createOrGrowPropertyStorage(m_butterfly.get(this), vm, this, structure(vm), oldSize, newSize); > + > + Butterfly* result = Butterfly::createOrGrowPropertyStorage(m_butterfly.get(this), vm, this, structure(vm), oldSize, newSize); > + > + return result;
I think this is not needed. Please revert.
Filip Pizlo
Comment 3
2016-02-05 10:34:14 PST
(In reply to
comment #2
)
> Comment on
attachment 270724
[details]
> the patch > > View in context: >
https://bugs.webkit.org/attachment.cgi?id=270724&action=review
> > > Source/JavaScriptCore/runtime/JSObject.cpp:597 > > - // this case if we ever cared. > > - enterDictionaryIndexingModeWhenArrayStorageAlreadyExists(vm, ensureArrayStorageSlow(vm)); > > + // this case if we ever cared. Note that ensureArrayStorage() can return null if the object > > + // doesn't support traditional indexed properties. At the time of writing, this just affects > > + // typed arrays. > > + if (ArrayStorage* storage = ensureArrayStorageSlow(vm)) > > + enterDictionaryIndexingModeWhenArrayStorageAlreadyExists(vm, storage); > > JSObject::enterDictionaryIndexingMode() seems to be called from > JSArray::setLengthWritable() and JSObject::preventExtensions() with the > assumption that it will succeed in entering indexing mode. Can you please > explain why it is ok to simply do nothing is we fail to > ensureArrayStorageSlow()?
JSArray will always return non-null from ensureArrayStorageSlow(), since a JSArray is not a typed array.
> > > Source/JavaScriptCore/runtime/JSObject.cpp:2548 > > - > > - return Butterfly::createOrGrowPropertyStorage(m_butterfly.get(this), vm, this, structure(vm), oldSize, newSize); > > + > > + Butterfly* result = Butterfly::createOrGrowPropertyStorage(m_butterfly.get(this), vm, this, structure(vm), oldSize, newSize); > > + > > + return result; > > I think this is not needed. Please revert.
Sure.
Filip Pizlo
Comment 4
2016-02-05 10:36:56 PST
(In reply to
comment #3
)
> (In reply to
comment #2
) > > Comment on
attachment 270724
[details]
> > the patch > > > > View in context: > >
https://bugs.webkit.org/attachment.cgi?id=270724&action=review
> > > > > Source/JavaScriptCore/runtime/JSObject.cpp:597 > > > - // this case if we ever cared. > > > - enterDictionaryIndexingModeWhenArrayStorageAlreadyExists(vm, ensureArrayStorageSlow(vm)); > > > + // this case if we ever cared. Note that ensureArrayStorage() can return null if the object > > > + // doesn't support traditional indexed properties. At the time of writing, this just affects > > > + // typed arrays. > > > + if (ArrayStorage* storage = ensureArrayStorageSlow(vm)) > > > + enterDictionaryIndexingModeWhenArrayStorageAlreadyExists(vm, storage); > > > > JSObject::enterDictionaryIndexingMode() seems to be called from > > JSArray::setLengthWritable() and JSObject::preventExtensions() with the > > assumption that it will succeed in entering indexing mode. Can you please > > explain why it is ok to simply do nothing is we fail to > > ensureArrayStorageSlow()? > > JSArray will always return non-null from ensureArrayStorageSlow(), since a > JSArray is not a typed array.
And typed arrays are unaffected by things like preventExtensions(). Broadly, there's no effect on typed arrays from doing enterDictionaryIndexingMode() since typed arrays override normal JS indexing behavior already and so we just need to make sure that the usual JSObject indexing stuff doesn't do anything. In trunk, JSObject indexing stuff sometimes corrupts the typed array's state, and this patch fixes that.
Mark Lam
Comment 5
2016-02-05 10:40:08 PST
Comment on
attachment 270724
[details]
the patch View in context:
https://bugs.webkit.org/attachment.cgi?id=270724&action=review
r=me
>>>> Source/JavaScriptCore/runtime/JSObject.cpp:597 >>>> + enterDictionaryIndexingModeWhenArrayStorageAlreadyExists(vm, storage); >>> >>> JSObject::enterDictionaryIndexingMode() seems to be called from JSArray::setLengthWritable() and JSObject::preventExtensions() with the assumption that it will succeed in entering indexing mode. Can you please explain why it is ok to simply do nothing is we fail to ensureArrayStorageSlow()? >> >> JSArray will always return non-null from ensureArrayStorageSlow(), since a JSArray is not a typed array. > > And typed arrays are unaffected by things like preventExtensions(). Broadly, there's no effect on typed arrays from doing enterDictionaryIndexingMode() since typed arrays override normal JS indexing behavior already and so we just need to make sure that the usual JSObject indexing stuff doesn't do anything. > > In trunk, JSObject indexing stuff sometimes corrupts the typed array's state, and this patch fixes that.
Sounds good. I feel like we should have an else case here for when !storage, and ASSERT that the self object is a TypedArray in that case.
Filip Pizlo
Comment 6
2016-02-05 11:20:30 PST
(In reply to
comment #5
)
> Comment on
attachment 270724
[details]
> the patch > > View in context: >
https://bugs.webkit.org/attachment.cgi?id=270724&action=review
> > r=me > > >>>> Source/JavaScriptCore/runtime/JSObject.cpp:597 > >>>> + enterDictionaryIndexingModeWhenArrayStorageAlreadyExists(vm, storage); > >>> > >>> JSObject::enterDictionaryIndexingMode() seems to be called from JSArray::setLengthWritable() and JSObject::preventExtensions() with the assumption that it will succeed in entering indexing mode. Can you please explain why it is ok to simply do nothing is we fail to ensureArrayStorageSlow()? > >> > >> JSArray will always return non-null from ensureArrayStorageSlow(), since a JSArray is not a typed array. > > > > And typed arrays are unaffected by things like preventExtensions(). Broadly, there's no effect on typed arrays from doing enterDictionaryIndexingMode() since typed arrays override normal JS indexing behavior already and so we just need to make sure that the usual JSObject indexing stuff doesn't do anything. > > > > In trunk, JSObject indexing stuff sometimes corrupts the typed array's state, and this patch fixes that. > > Sounds good. I feel like we should have an else case here for when > !storage, and ASSERT that the self object is a TypedArray in that case.
If anything the assert would say something about hijacksIndexingHeader(). I created that method to make it easier to add other typed-array-like objects in the future.
Filip Pizlo
Comment 7
2016-02-05 11:52:45 PST
Landed in
http://trac.webkit.org/changeset/196179
Mark Lam
Comment 8
2016-07-13 14:07:52 PDT
***
Bug 153487
has been marked as a duplicate of this bug. ***
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug