@@ -202,8 +202,8 @@ GET_FIRST_ARGUMENT_AS(Tag)
202202#undef GET_FIRST_ARGUMENT_AS
203203
204204i::wasm::ModuleWireBytes GetFirstArgumentAsBytes (
205- const v8::FunctionCallbackInfo<v8::Value>& info, ErrorThrower* thrower ,
206- bool * is_shared) {
205+ const v8::FunctionCallbackInfo<v8::Value>& info, size_t max_length ,
206+ ErrorThrower* thrower, bool * is_shared) {
207207 DCHECK (i::ValidateCallbackInfo (info));
208208 const uint8_t * start = nullptr ;
209209 size_t length = 0 ;
@@ -234,7 +234,6 @@ i::wasm::ModuleWireBytes GetFirstArgumentAsBytes(
234234 if (length == 0 ) {
235235 thrower->CompileError (" BufferSource argument is empty" );
236236 }
237- size_t max_length = i::wasm::max_module_size ();
238237 if (length > max_length) {
239238 // The spec requires a CompileError for implementation-defined limits, see
240239 // https://webassembly.github.io/spec/js-api/index.html#limits.
@@ -644,7 +643,8 @@ void WebAssemblyCompileImpl(const v8::FunctionCallbackInfo<v8::Value>& info) {
644643 new AsyncCompilationResolver (isolate, context, promise_resolver));
645644
646645 bool is_shared = false ;
647- auto bytes = GetFirstArgumentAsBytes (info, &thrower, &is_shared);
646+ auto bytes = GetFirstArgumentAsBytes (info, i::wasm::max_module_size (),
647+ &thrower, &is_shared);
648648 if (thrower.error ()) {
649649 resolver->OnCompilationFailed (thrower.Reify ());
650650 return ;
@@ -676,8 +676,11 @@ void WasmStreamingCallbackForTesting(
676676 v8::WasmStreaming::Unpack (info.GetIsolate (), info.Data ());
677677
678678 bool is_shared = false ;
679+ // We don't check the buffer length up front, to allow d8 to test that the
680+ // streaming decoder implementation handles overly large inputs correctly.
681+ size_t unlimited = std::numeric_limits<size_t >::max ();
679682 i::wasm::ModuleWireBytes bytes =
680- GetFirstArgumentAsBytes (info, &thrower, &is_shared);
683+ GetFirstArgumentAsBytes (info, unlimited, &thrower, &is_shared);
681684 if (thrower.error ()) {
682685 streaming->Abort (Utils::ToLocal (thrower.Reify ()));
683686 return ;
@@ -778,7 +781,8 @@ void WebAssemblyValidateImpl(const v8::FunctionCallbackInfo<v8::Value>& info) {
778781 ErrorThrower thrower (i_isolate, " WebAssembly.validate()" );
779782
780783 bool is_shared = false ;
781- auto bytes = GetFirstArgumentAsBytes (info, &thrower, &is_shared);
784+ auto bytes = GetFirstArgumentAsBytes (info, i::wasm::max_module_size (),
785+ &thrower, &is_shared);
782786
783787 v8::ReturnValue<v8::Value> return_value = info.GetReturnValue ();
784788
@@ -857,7 +861,8 @@ void WebAssemblyModuleImpl(const v8::FunctionCallbackInfo<v8::Value>& info) {
857861 }
858862
859863 bool is_shared = false ;
860- auto bytes = GetFirstArgumentAsBytes (info, &thrower, &is_shared);
864+ auto bytes = GetFirstArgumentAsBytes (info, i::wasm::max_module_size (),
865+ &thrower, &is_shared);
861866
862867 if (thrower.error ()) {
863868 return ;
@@ -1175,7 +1180,8 @@ void WebAssemblyInstantiateImpl(
11751180 }
11761181
11771182 bool is_shared = false ;
1178- auto bytes = GetFirstArgumentAsBytes (info, &thrower, &is_shared);
1183+ auto bytes = GetFirstArgumentAsBytes (info, i::wasm::max_module_size (),
1184+ &thrower, &is_shared);
11791185 if (thrower.error ()) {
11801186 resolver->OnInstantiationFailed (thrower.Reify ());
11811187 return ;
0 commit comments