apply an explicit max vector length check (issue #636)

This commit is contained in:
Alex Shinn 2020-05-22 14:13:48 +09:00
parent b459e11ecf
commit 61f2983fad
2 changed files with 7 additions and 1 deletions

View file

@ -787,6 +787,10 @@
#define SEXP_MAX_STACK_SIZE SEXP_INIT_STACK_SIZE*1000
#endif
#ifndef SEXP_MAX_VECTOR_LENGTH
#define SEXP_MAX_VECTOR_LENGTH (SEXP_MAX_FIXNUM >> 1)
#endif
#ifndef SEXP_DEFAULT_EQUAL_DEPTH
#define SEXP_DEFAULT_EQUAL_DEPTH 10000
#endif

4
sexp.c
View file

@ -1524,8 +1524,10 @@ sexp sexp_string_to_symbol_op (sexp ctx, sexp self, sexp_sint_t n, sexp str) {
sexp sexp_make_vector_op (sexp ctx, sexp self, sexp_sint_t n, sexp len, sexp dflt) {
sexp vec, *x;
int i, clen = sexp_unbox_fixnum(len);
sexp_sint_t i, clen = sexp_unbox_fixnum(len);
if (! clen) return sexp_global(ctx, SEXP_G_EMPTY_VECTOR);
if (clen < 0 || clen > SEXP_MAX_VECTOR_LENGTH)
return sexp_xtype_exception(ctx, self, "vector length out of range", len);
vec = sexp_alloc_tagged(ctx, sexp_sizeof(vector) + clen*sizeof(sexp),
SEXP_VECTOR);
if (sexp_exceptionp(vec)) return vec;