Usually, we try to pre-allocate a few extra stack values for
convenience, but we don't actually need to. Avoid a buffer overflow in
the case where this "extra" was causing us to go over INT32_MAX.
This commit is contained in:
Calvin Rose
2026-04-26 13:23:03 -05:00
parent ed17dd2c59
commit d9b1d711ea
+6 -1
View File
@@ -1111,7 +1111,12 @@ static const uint8_t *unmarshal_one_fiber(
}
/* Allocate stack memory */
fiber->capacity = fiber_stacktop + 10;
if (fiber_stacktop < INT32_MAX - 10) {
fiber->capacity = fiber_stacktop + 10;
} else {
/* Extra capacity is usually nice to avoid immediately reallocing on pushed arguments, but not needed */
fiber->capacity = INT32_MAX;
}
fiber->data = janet_malloc(sizeof(Janet) * fiber->capacity);
if (!fiber->data) {
JANET_OUT_OF_MEMORY;