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>
// 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
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")
+ }
+}