pelletier / go-toml

Go library for the TOML file format
https://github.com/pelletier/go-toml
Other
1.73k stars 211 forks source link

Fix zone offset in time parser #690

Closed moorereason closed 2 years ago

moorereason commented 2 years ago

Describe the bug Given 0=0000-01-01 00:00:00+27000, go-toml doesn't return an error on the time zone offset.

$ echo "0=0000-01-01 00:00:00+27000" | gotoml-test-decoder
{
  "0": {
    "type": "datetime",
    "value": "0000-01-01T00:00:00+27:00"
  }
}

To Reproduce https://go.dev/play/p/fES37UrI64-

toml.Unmarshal([]byte("0=0000-01-01 00:00:00+27000"), &v)

Expected behavior I expected to see an error on invalid time zone offset since it has 5 digits instead of the max of 4. Per RFC3339/ISO8601 ABNF:

time-hour         = 2DIGIT ; 00-24
time-minute       = 2DIGIT ; 00-59
time-numoffset    = ("+" / "-") time-hour [[":"] time-minute]

Versions

Additional context Found while doing differential fuzzing against toml-dart.

pelletier commented 2 years ago

Should be fixed in https://github.com/pelletier/go-toml/commit/3990899d7eec45790be0f4a5344e387a89098181.