You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ArrayBuffer.isView / util.types.isArrayBufferView / isUint8Array return false for a Node Buffer (breaks bson UUID decode in mongodb) #11239
ArrayBuffer.isView(buf), util.types.isArrayBufferView(buf) and util.types.isUint8Array(buf) all return false for a Node Buffer under Perry. Node returns true for all three (a Buffer is a Uint8Array). buf instanceof Uint8Array is already true under Perry, so only these predicates are wrong.
Repro (no packages)
import{types}from"node:util";constbuf=Buffer.alloc(4);constisView=ArrayBuffer.isView;console.log(ArrayBuffer.isView(buf));// direct callconsole.log(isView(buf));// through the value (thunk path)console.log(types.isArrayBufferView(buf));console.log(types.isUint8Array(buf));console.log(ArrayBuffer.isView(Buffer.from("abc")));console.log(ArrayBuffer.isView(buf.subarray(1,3)));console.log(ArrayBuffer.isView(Buffer.from(newArrayBuffer(32),8,16)));console.log(ArrayBuffer.isView(newUint8Array(4)));// controlconsole.log(bufinstanceofUint8Array);// control
Checked with PERRY_NO_AUTO_OPTIMIZE=1 on perrymaster (linux-x64).
Where
The direct call ArrayBuffer.isView(x) lowers to util/types.isArrayBufferView (crates/perry-hir/src/lower/expr_call/module_static.rs).
js_util_types_is_array_buffer_view (crates/perry-runtime/src/object/util_types.rs) accepts is_uint8array_buffer(addr) || is_data_view(addr) || typed_array_kind(..). None of these recognise a BufferHeader registered only through register_buffer (is_registered_buffer), which is what Buffer.alloc / Buffer.from / buf.subarray produce.
array_buffer_is_view_thunk (crates/perry-runtime/src/object/global_this/typed_array.rs) has the same predicate, so the value-call form fails the same way.
js_util_types_is_uint8_array goes through jsvalue_typed_array_kind only, which also misses Buffers.
Real-world impact
This breaks the npm mongodb driver compiled from source. bson 7.3.3 decodes every binary subtype-4 value (UUID) as new UUID(buffer.subarray(...)), and UUID's constructor accepts the bytes only if ArrayBuffer.isView(input) && input.byteLength === 16. Under Perry that check is false, so the constructor throws:
BSONError: Argument passed in UUID constructor must be a UUID, a 16 byte Buffer or a 32/36 character hex string ...
A plain db.listCollections().toArray() hits it, because the server includes each collection's info.uuid. So does reading back any document that stores a UUID. This is the only failure left in a broad mongodb 7.5.0 probe (CRUD, cursors, bulkWrite, indexes, aggregate, transactions, change streams) run against mongod 8.0.4. It is what blocks removing the native perry-ext-mongodb binding.
Activity
fix(runtime): one view classifier for Buffer/typed-array predicates (#…