Fix leap second overflow in datetime parsing (#1015)
Normalize leap seconds (second=60) to second=59 before passing to time.Date() to prevent year overflow. When Go's time.Date() receives second=60, it normalizes the time by adding 1 minute, which can cause dates like 9999-12-31 23:59:60 to overflow to year 10000 - outside the valid TOML date range (0000-9999). This fix ensures that timestamps with leap seconds can be successfully round-tripped (parsed and re-serialized) without causing parsing errors. Fixes OSS-Fuzz issue 472183443
This commit is contained in:
+7
-1
@@ -94,7 +94,13 @@ type LocalDateTime struct {
|
||||
|
||||
// AsTime converts d into a specific time instance in zone.
|
||||
func (d LocalDateTime) AsTime(zone *time.Location) time.Time {
|
||||
return time.Date(d.Year, time.Month(d.Month), d.Day, d.Hour, d.Minute, d.Second, d.Nanosecond, zone)
|
||||
// Normalize leap seconds (second=60) to second=59 to prevent overflow
|
||||
// when Go's time.Date normalizes the time.
|
||||
second := d.Second
|
||||
if second == 60 {
|
||||
second = 59
|
||||
}
|
||||
return time.Date(d.Year, time.Month(d.Month), d.Day, d.Hour, d.Minute, second, d.Nanosecond, zone)
|
||||
}
|
||||
|
||||
// String returns RFC 3339 representation of d.
|
||||
|
||||
Reference in New Issue
Block a user