Skip to content

Commit

Permalink
Decoder: validate bounds of day and month in dates (#680)
Browse files Browse the repository at this point in the history
Fixes #676
  • Loading branch information
pelletier authored Nov 24, 2021
1 parent 2b3de62 commit 8eae15b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ func checkAndRemoveUnderscoresFloats(b []byte) ([]byte, error) {

// isValidDate checks if a provided date is a date that exists.
func isValidDate(year int, month int, day int) bool {
return day <= daysIn(month, year)
return month > 0 && month < 13 && day > 0 && day <= daysIn(month, year)
}

// daysBefore[m] counts the number of days in a non-leap year
Expand Down
8 changes: 8 additions & 0 deletions unmarshaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2570,6 +2570,14 @@ world'`,
desc: `invalid month`,
data: `a=2021-0--29`,
},
{
desc: `zero is an invalid day`,
data: `a=2021-11-00`,
},
{
desc: `zero is an invalid month`,
data: `a=2021-00-11`,
},
{
desc: `carriage return inside basic key`,
data: "\"\r\"=42",
Expand Down

0 comments on commit 8eae15b

Please sign in to comment.