array.c: new configuration MRB_ARY_LENGTH_MAX.

The default value is 2**17 entries. If you want to avoid the limitation,
set this value to 0.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2022-07-25 08:11:25 +09:00
parent c4cb416460
commit 13d909bd3c
2 changed files with 12 additions and 0 deletions
+5
View File
@@ -112,6 +112,11 @@
/* set this value to zero to skip the check */
//#define MRB_STR_LENGTH_MAX 1048576
/* maximum length of arrays */
/* the default value is 2**17 entries */
/* set this value to zero to skip the check */
//#define MRB_ARY_LENGTH_MAX 131072
/* argv max size in mrb_funcall */
//#define MRB_FUNCALL_ARGC_MAX 16
+7
View File
@@ -17,6 +17,9 @@
#define ARY_DEFAULT_LEN 4
#define ARY_SHRINK_RATIO 5 /* must be larger than 2 */
#define ARY_C_MAX_SIZE (SIZE_MAX / sizeof(mrb_value))
#ifndef MRB_ARY_LENGTH_MAX
#define MRB_ARY_LENGTH_MAX 131072
#endif
#define ARY_MAX_SIZE ((mrb_int)((ARY_C_MAX_SIZE < (size_t)MRB_INT_MAX) ? ARY_C_MAX_SIZE : MRB_INT_MAX-1))
static void
@@ -30,6 +33,10 @@ ary_check_too_big(mrb_state *mrb, mrb_int a, mrb_int b)
{
if (a > ARY_MAX_SIZE - b || a < 0)
ary_too_big(mrb);
#if MRB_ARY_LENGTH_MAX != 0
if (a > MRB_ARY_LENGTH_MAX - b || a < 0)
ary_too_big(mrb);
#endif
}
static struct RArray*