providers: improve time parsing error checking

This commit is contained in:
Steven Allen 2019-04-12 18:33:30 -07:00
parent 069736916d
commit 2a3899be0d

View File

@ -148,14 +148,12 @@ func loadProvSet(dstore ds.Datastore, k cid.Cid) (*providerSet, error) {
return out, nil
}
func readTimeValue(i interface{}) (time.Time, error) {
data, ok := i.([]byte)
if !ok {
return time.Time{}, fmt.Errorf("data was not a []byte")
func readTimeValue(data []byte) (time.Time, error) {
nsec, n := binary.Varint(data)
if n <= 0 {
return time.Time{}, fmt.Errorf("failed to parse time")
}
nsec, _ := binary.Varint(data)
return time.Unix(0, nsec), nil
}