Skip to content

[vm/ffi] Pointer.asTypedList shared across isolates causes use after free #55800

Open
@dcharkes

Description

@dcharkes

The native finalizers in asTypedList are bound to an isolate, not an isolate group:

sdk/sdk/lib/ffi/ffi.dart

Lines 368 to 373 in 4dd6ee6

external Int8List asTypedList(
int length, {
@Since('3.1') Pointer<NativeFinalizerFunction>? finalizer,
@Since('3.1') Pointer<Void>? token,
});
}

final _asTypedListFinalizer = _NativeFinalizer(_asTypedListFinalizerCallback);

Hypothesis: The TypedData we create out of Pointer is marked unmodifiable.

We need to either mark the typed data as mutable so that the view does not consider the typed data as unmodifiable, and we copy instead of share the object.
Or, we need to attach finalizers in the isolate group instead of the isolate.

Context:

TODO: verify hypothesis. (Filing issue so that I don't forget.)

Metadata

Metadata

Labels

area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.library-ffitriagedIssue has been triaged by sub team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions