@@ -273,6 +273,14 @@ namespace Js
273273
274274 ScriptContext * scriptContext = externalFunction->type ->GetScriptContext ();
275275 AnalysisAssert (scriptContext);
276+
277+ if (args.Info .Count > USHORT_MAX)
278+ {
279+ // Due to compat reasons, stdcall external functions expect a ushort count of args.
280+ // To support more than this we will need a new API.
281+ Js::JavascriptError::ThrowTypeError (scriptContext, JSERR_ArgListTooLarge);
282+ }
283+
276284 Var result = NULL ;
277285
278286#if ENABLE_TTD
@@ -284,14 +292,15 @@ namespace Js
284292 {
285293 BEGIN_LEAVE_SCRIPT (scriptContext)
286294 {
287- result = externalFunction->stdCallNativeMethod (function, ((callInfo.Flags & CallFlags_New) != 0 ), args.Values , args.Info .Count , externalFunction->callbackState );
295+ // ArgCount truncation has been verified above.
296+ result = externalFunction->stdCallNativeMethod (function, ((callInfo.Flags & CallFlags_New) != 0 ), args.Values , static_cast <USHORT>(args.Info .Count ), externalFunction->callbackState );
288297 }
289298 END_LEAVE_SCRIPT (scriptContext);
290299 }
291300#else
292301 BEGIN_LEAVE_SCRIPT (scriptContext)
293302 {
294- result = externalFunction->stdCallNativeMethod (function, ((callInfo.Flags & CallFlags_New) != 0 ), args.Values , args.Info .Count , externalFunction->callbackState );
303+ result = externalFunction->stdCallNativeMethod (function, ((callInfo.Flags & CallFlags_New) != 0 ), args.Values , static_cast <USHORT>( args.Info .Count ) , externalFunction->callbackState );
295304 }
296305 END_LEAVE_SCRIPT (scriptContext);
297306#endif
@@ -417,6 +426,13 @@ namespace Js
417426 }
418427 else
419428 {
429+ if (args.Info .Count > USHORT_MAX)
430+ {
431+ // Due to compat reasons, stdcall external functions expect a ushort count of args.
432+ // To support more than this we will need a new API.
433+ Js::JavascriptError::ThrowTypeError (scriptContext, JSERR_ArgListTooLarge);
434+ }
435+
420436 TTDAssert (scriptContext->ShouldPerformRecordAction (), " Check either record/replay before calling!!!" );
421437
422438 TTD::EventLog* elog = scriptContext->GetThreadContext ()->TTDLog ;
@@ -426,7 +442,8 @@ namespace Js
426442
427443 BEGIN_LEAVE_SCRIPT (scriptContext)
428444 {
429- result = externalFunction->stdCallNativeMethod (function, ((callInfo.Flags & CallFlags_New) != 0 ), args.Values , args.Info .Count , externalFunction->callbackState );
445+ // ArgCount truncation has been verified above.
446+ result = externalFunction->stdCallNativeMethod (function, ((callInfo.Flags & CallFlags_New) != 0 ), args.Values , static_cast <ushort>(args.Info .Count ), externalFunction->callbackState );
430447 }
431448 END_LEAVE_SCRIPT (scriptContext);
432449
0 commit comments