mruby-time: fix integer overflow in timegm() year calculation

OUTINT macro checked ayear > INT_MAX, but timegm() later computes
tm_year + TM_YEAR_BASE (1900), which overflows when tm_year is near
INT_MAX. Tighten the upper bound to INT_MAX - TM_YEAR_BASE.

Found by ClusterFuzz.

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2026-02-10 23:34:30 +09:00
parent 5970e3508e
commit 5d3aab8b22
+1 -1
View File
@@ -651,7 +651,7 @@ time_mktime(mrb_state *mrb, mrb_int ayear, mrb_int amonth, mrb_int aday,
struct tm nowtime = { 0 };
#if MRB_INT_MAX > INT_MAX
#define OUTINT(x) (((MRB_TIME_T_UINT ? 0 : INT_MIN) > (x)) || (x) > INT_MAX)
#define OUTINT(x) (((MRB_TIME_T_UINT ? 0 : INT_MIN) > (x)) || (x) > INT_MAX - TM_YEAR_BASE)
#else
#define OUTINT(x) 0
#endif