diff --git a/src/dawn/node/binding/Converter.cpp b/src/dawn/node/binding/Converter.cpp index e645c44dc1..94c91d62e8 100644 --- a/src/dawn/node/binding/Converter.cpp +++ b/src/dawn/node/binding/Converter.cpp @@ -153,15 +153,20 @@ bool Converter::Convert(wgpu::ImageCopyBuffer& out, const interop::GPUImageCopyB bool Converter::Convert(BufferSource& out, interop::BufferSource in) { out = {}; if (auto* view = std::get_if(&in)) { - std::visit( + return std::visit( [&](auto&& v) { auto arr = v.ArrayBuffer(); - out.data = arr.Data(); - out.size = arr.ByteLength(); + if (v.ByteOffset() + v.ByteLength() > arr.ByteLength()) { + Napi::Error::New(env, "offset + length exceeds underlying buffer size") + .ThrowAsJavaScriptException(); + return false; + } + out.data = static_cast(arr.Data()) + v.ByteOffset(); + out.size = v.ByteLength(); out.bytesPerElement = v.ElementSize(); + return true; }, *view); - return true; } if (auto* arr = std::get_if(&in)) { out.data = arr->Data();