Decoder: validate bounds of day and month in dates (#680)

Fixes #676
This commit is contained in:
Thomas Pelletier
2021-11-24 17:42:01 -05:00
committed by GitHub
parent 2b3de620e8
commit 8eae15b2ee
2 changed files with 9 additions and 1 deletions
+1 -1
View File
@@ -462,7 +462,7 @@ func checkAndRemoveUnderscoresFloats(b []byte) ([]byte, error) {
// isValidDate checks if a provided date is a date that exists. // isValidDate checks if a provided date is a date that exists.
func isValidDate(year int, month int, day int) bool { 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 // daysBefore[m] counts the number of days in a non-leap year
+8
View File
@@ -2570,6 +2570,14 @@ world'`,
desc: `invalid month`, desc: `invalid month`,
data: `a=2021-0--29`, 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`, desc: `carriage return inside basic key`,
data: "\"\r\"=42", data: "\"\r\"=42",