diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-05-20 17:50:56 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-05-20 17:50:56 -0300 |
commit | c15543b9afa31ab5dc564511ae11acd808405e8f (patch) | |
tree | 61adad4a35a283342abd8366b9fbed1fadcab423 | |
parent | be05c444818989463dc307eed283503d391f93eb (diff) | |
download | lua-c15543b9afa31ab5dc564511ae11acd808405e8f.tar.gz lua-c15543b9afa31ab5dc564511ae11acd808405e8f.tar.bz2 lua-c15543b9afa31ab5dc564511ae11acd808405e8f.zip |
Bug: check for constructor overflow in [exp] fields
The check for constructor overflow was considering only fields with
explicit names, ignoring fields with syntax '[exp]=exp'.
-rw-r--r-- | lopcodes.h | 6 | ||||
-rw-r--r-- | lparser.c | 5 |
2 files changed, 5 insertions, 6 deletions
@@ -254,7 +254,7 @@ OP_SETTABLE,/* A B C R[A][R[B]] := RK(C) */ | |||
254 | OP_SETI,/* A B C R[A][B] := RK(C) */ | 254 | OP_SETI,/* A B C R[A][B] := RK(C) */ |
255 | OP_SETFIELD,/* A B C R[A][K[B]:shortstring] := RK(C) */ | 255 | OP_SETFIELD,/* A B C R[A][K[B]:shortstring] := RK(C) */ |
256 | 256 | ||
257 | OP_NEWTABLE,/* A B C k R[A] := {} */ | 257 | OP_NEWTABLE,/* A vB vC k R[A] := {} */ |
258 | 258 | ||
259 | OP_SELF,/* A B C R[A+1] := R[B]; R[A] := R[B][K[C]:shortstring] */ | 259 | OP_SELF,/* A B C R[A+1] := R[B]; R[A] := R[B][K[C]:shortstring] */ |
260 | 260 | ||
@@ -378,9 +378,9 @@ OP_EXTRAARG/* Ax extra (larger) argument for previous opcode */ | |||
378 | real C = EXTRAARG _ C (the bits of EXTRAARG concatenated with the | 378 | real C = EXTRAARG _ C (the bits of EXTRAARG concatenated with the |
379 | bits of C). | 379 | bits of C). |
380 | 380 | ||
381 | (*) In OP_NEWTABLE, B is log2 of the hash size (which is always a | 381 | (*) In OP_NEWTABLE, vB is log2 of the hash size (which is always a |
382 | power of 2) plus 1, or zero for size zero. If not k, the array size | 382 | power of 2) plus 1, or zero for size zero. If not k, the array size |
383 | is C. Otherwise, the array size is EXTRAARG _ C. | 383 | is vC. Otherwise, the array size is EXTRAARG _ vC. |
384 | 384 | ||
385 | (*) For comparisons, k specifies what condition the test should accept | 385 | (*) For comparisons, k specifies what condition the test should accept |
386 | (true or false). | 386 | (true or false). |
@@ -904,12 +904,11 @@ static void recfield (LexState *ls, ConsControl *cc) { | |||
904 | FuncState *fs = ls->fs; | 904 | FuncState *fs = ls->fs; |
905 | lu_byte reg = ls->fs->freereg; | 905 | lu_byte reg = ls->fs->freereg; |
906 | expdesc tab, key, val; | 906 | expdesc tab, key, val; |
907 | if (ls->t.token == TK_NAME) { | 907 | if (ls->t.token == TK_NAME) |
908 | luaY_checklimit(fs, cc->nh, INT_MAX / 2, "items in a constructor"); | ||
909 | codename(ls, &key); | 908 | codename(ls, &key); |
910 | } | ||
911 | else /* ls->t.token == '[' */ | 909 | else /* ls->t.token == '[' */ |
912 | yindex(ls, &key); | 910 | yindex(ls, &key); |
911 | luaY_checklimit(fs, cc->nh, INT_MAX / 2, "items in a constructor"); | ||
913 | cc->nh++; | 912 | cc->nh++; |
914 | checknext(ls, '='); | 913 | checknext(ls, '='); |
915 | tab = *cc->t; | 914 | tab = *cc->t; |