@@ -996,6 +996,44 @@ static void backtrace_oom_current_exception(void)
996996 JS_FreeRuntime (rt );
997997}
998998
999+ static void proxy_own_keys_huge_length (void )
1000+ {
1001+ static const char setup_code [] =
1002+ "globalThis.p = new Proxy({}, {\n"
1003+ " ownKeys() { return { length: 0x20000000 }; },\n"
1004+ "});" ;
1005+ JSMemoryUsage stats ;
1006+ JSValue ret , exception ;
1007+ JSRuntime * rt ;
1008+ JSContext * ctx ;
1009+ const char * str ;
1010+
1011+ rt = new_runtime ();
1012+ ctx = JS_NewContext (rt );
1013+
1014+ ret = eval (ctx , setup_code );
1015+ assert (!JS_IsException (ret ));
1016+ JS_FreeValue (ctx , ret );
1017+
1018+ JS_ComputeMemoryUsage (rt , & stats );
1019+ JS_SetMemoryLimit (rt , (size_t )stats .malloc_size + 128 * 1024 );
1020+
1021+ ret = eval (ctx , "Object.keys(p)" );
1022+ assert (JS_IsException (ret ));
1023+ JS_FreeValue (ctx , ret );
1024+ exception = JS_GetException (ctx );
1025+ str = JS_ToCString (ctx , exception );
1026+ assert (str );
1027+ /* the trap result has no index 0, so the first key must be rejected */
1028+ assert (!strcmp (str , "TypeError: proxy: properties must be strings or symbols" ));
1029+ JS_FreeCString (ctx , str );
1030+ JS_FreeValue (ctx , exception );
1031+ JS_SetMemoryLimit (rt , 0 );
1032+
1033+ JS_FreeContext (ctx );
1034+ JS_FreeRuntime (rt );
1035+ }
1036+
9991037static int gop_get_own_property (JSContext * ctx , JSPropertyDescriptor * desc ,
10001038 JSValueConst obj , JSAtom prop )
10011039{
@@ -1452,6 +1490,7 @@ int main(void)
14521490 new_errors ();
14531491 backtrace_oom_current_exception ();
14541492 backtrace_oom_callsite_array ();
1493+ proxy_own_keys_huge_length ();
14551494 global_object_prototype ();
14561495 slice_string_tocstring ();
14571496 immutable_array_buffer ();
0 commit comments