Skip to content
This repository was archived by the owner on Oct 24, 2023. It is now read-only.

AtomicReadModifyWrite is not checking shrunk ArrayBuffer after ToIntegerOrInfinity #104

Closed
Constellation opened this issue Nov 15, 2022 · 3 comments · Fixed by #110
Closed

Comments

@Constellation
Copy link
Member

Constellation commented Nov 15, 2022

Right now, AtomicReadModifyWrite is only checking detached buffer after [ToIntegerOrInfinity](https://tc39.es/ecma262/#sec-tointegerorinfinity). This means that, if shrinking happens via this toIntegerOrInfinity, then indexedPosition can be out-of-bounds in non-shared ArrayBuffer.
Note that Atomics RMW operations can be performed onto non-shared ArrayBuffer-backing TypedArrays. (While notify / wait etc. works only for SharedArrayBuffer-backing TypedArrays). Thus, shrinking can happen via resize method.

Also, note that ValidateAtomicAccess happens before performing ToIntegerOrInfinity, so we need yet another check basically.

https://tc39.es/ecma262/#sec-atomicreadmodifywrite

@Constellation
Copy link
Member Author

Also, this can be applied to Atomics.store etc.

@Constellation
Copy link
Member Author

Constellation commented Nov 15, 2022

var buffer = new ArrayBuffer(128, { maxByteLength: 1024 });
var typedArray = new Int32Array(buffer);
Atomics.and(typedArray, 4, { valueOf() { buffer.resize(0); return 0; } });

@syg
Copy link
Collaborator

syg commented Nov 15, 2022

Thanks, yep, that sounds right to me. Looks to me like those IsDetached calls need to be replaced with IsIntegerIndexedObjectOutOfBounds.

Correction: IsIntegerIndexedObjectOutOfBounds isn't sufficient, we also need to recheck the index < length.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants