Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions service/worker/scheduler/calendar.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@ type (
const (
// minCalendarYear is the smallest year that can appear in a calendar spec.
minCalendarYear = 2000
// maxCalendarYear is the latest year that will be recognized for calendar dates.
// If you're still using Temporal in 2100 please change this constant and rebuild.
// maxCalendarYear is the latest year that will be calculated for calendar dates.
// This protects against DoS from calculating far into the future. Specs can reference
// years beyond this limit, but actual calculation will stop here. Future server versions
// can safely increase this limit.
maxCalendarYear = 2100
// maxSpecYear is the largest year allowed in a schedule spec. This is set to a very
// large value to effectively remove the restriction while still preventing absurd values.
maxSpecYear = 9999

// max length of one calendar comment field
maxCommentLen = 200
Expand Down Expand Up @@ -229,7 +234,7 @@ func parseCalendarToStructured(cal *schedulepb.CalendarSpec) (*schedulepb.Struct
DayOfWeek: makeRangeOrNil(cal.DayOfWeek, "DayOfWeek", "*", 0, 7, parseModeDow),
DayOfMonth: makeRangeOrNil(cal.DayOfMonth, "DayOfMonth", "*", 1, 31, parseModeInt),
Month: makeRangeOrNil(cal.Month, "Month", "*", 1, 12, parseModeMonth),
Year: makeRangeOrNil(cal.Year, "Year", "*", minCalendarYear, maxCalendarYear, parseModeYear),
Year: makeRangeOrNil(cal.Year, "Year", "*", minCalendarYear, maxSpecYear, parseModeYear),
Comment: cal.Comment,
}
if len(errs) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion service/worker/scheduler/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func validateStructuredCalendar(scs *schedulepb.StructuredCalendarSpec) error {
checkRanges(scs.Hour, "Hour", 0, 23)
checkRanges(scs.DayOfMonth, "DayOfMonth", 1, 31)
checkRanges(scs.Month, "Month", 1, 12)
checkRanges(scs.Year, "Year", minCalendarYear, maxCalendarYear)
checkRanges(scs.Year, "Year", minCalendarYear, maxSpecYear)
checkRanges(scs.DayOfWeek, "DayOfWeek", 0, 6)

if len(scs.Comment) > maxCommentLen {
Expand Down
14 changes: 13 additions & 1 deletion service/worker/scheduler/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ func (s *specSuite) TestCanonicalize() {
{DayOfWeek: []*schedulepb.Range{{Start: 7}}},
{DayOfWeek: []*schedulepb.Range{{Start: 6, End: 7}}},
{Year: []*schedulepb.Range{{Start: 1999}}},
{Year: []*schedulepb.Range{{Start: 2112}}},
} {
_, err = canonicalizeSpec(&schedulepb.ScheduleSpec{
StructuredCalendar: []*schedulepb.StructuredCalendarSpec{scs},
Expand Down Expand Up @@ -494,3 +493,16 @@ func (s *specSuite) TestSpecJitterSeed() {
time.Date(2022, 3, 24, 0, 39, 16, 922000000, time.UTC),
)
}

func (s *specSuite) TestSpecFarFutureYear() {
s.checkSequenceFull(
"",
&schedulepb.ScheduleSpec{
Calendar: []*schedulepb.CalendarSpec{
{Hour: "12", Minute: "0", DayOfMonth: "1", Month: "1", Year: "2150"},
},
},
time.Date(2099, 1, 1, 0, 0, 0, 0, time.UTC),
time.Time{}, // returns zero time since 2150 is beyond calculation bound
)
}