mirror of
https://github.com/golang/go
synced 2024-11-23 09:10:08 -07:00
time: reject tzdata with no zones
Fixes #29437 Change-Id: Ice0a03a543e564d66651bfdfce5cd32ebaa35926 Reviewed-on: https://go-review.googlesource.com/c/155746 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
9892ccff23
commit
58bf401293
@ -216,7 +216,13 @@ func LoadLocationFromTZData(name string, data []byte) (*Location, error) {
|
||||
// Now we can build up a useful data structure.
|
||||
// First the zone information.
|
||||
// utcoff[4] isdst[1] nameindex[1]
|
||||
zone := make([]zone, n[NZone])
|
||||
nzone := n[NZone]
|
||||
if nzone == 0 {
|
||||
// Reject tzdata files with no zones. There's nothing useful in them.
|
||||
// This also avoids a panic later when we add and then use a fake transition (golang.org/issue/29437).
|
||||
return nil, badData
|
||||
}
|
||||
zone := make([]zone, nzone)
|
||||
for i := range zone {
|
||||
var ok bool
|
||||
var n uint32
|
||||
|
@ -173,3 +173,12 @@ func TestEarlyLocation(t *testing.T) {
|
||||
t.Errorf("Zone offset == %d, want %d", tzOffset, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMalformedTZData(t *testing.T) {
|
||||
// The goal here is just that malformed tzdata results in an error, not a panic.
|
||||
issue29437 := "TZif\x00000000000000000\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0000"
|
||||
_, err := time.LoadLocationFromTZData("abc", []byte(issue29437))
|
||||
if err == nil {
|
||||
t.Error("expected error, got none")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user