diff --git a/include/chibi/features.h b/include/chibi/features.h index 2a90172c..ceae2b46 100644 --- a/include/chibi/features.h +++ b/include/chibi/features.h @@ -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 diff --git a/sexp.c b/sexp.c index 63353867..5ce4eb68 100644 --- a/sexp.c +++ b/sexp.c @@ -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;