Skip to content

Replace NativeBufferFactory with a more secure implementation #3062

Open
@kewde

Description

@kewde

Description

Skia.NativeBuffer is badly designed.

The MakeFromImage function sadly returns pointers as BigInts.

JSI_HOST_FUNCTION(MakeFromImage) {
auto image = JsiSkImage::fromValue(runtime, arguments[0]);
image->makeNonTextureImage();
uint64_t pointer = getContext()->makeNativeBuffer(image);
return jsi::BigInt::fromUint64(runtime, pointer);
}

The Release function accepts a BigInt argument, which is expected to be the pointer for which the memory should be freed. It should've encapsulated the pointers and restricted this with a check to ensure the value can't be tampered with from JavaScript side.

JSI_HOST_FUNCTION(Release) {
jsi::BigInt pointer = arguments[0].asBigInt(runtime);
const uintptr_t nativeBufferPointer = pointer.asUint64(runtime);
getContext()->releaseNativeBuffer(nativeBufferPointer);
return jsi::Value::undefined();
}

Ideally, the JavaScript side does not get an arbitrary way to free any hardware pointers beyond the ones it's explicitly been granted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions