diff --git a/lib/encoding/encoding.go b/lib/encoding/encoding.go index b53ee22842..89168529d5 100644 --- a/lib/encoding/encoding.go +++ b/lib/encoding/encoding.go @@ -42,6 +42,20 @@ const ( MarshalTypeNearestDelta = MarshalType(6) ) +// NeedsValidation returns true if mt may need additional validation for silent data corruption. +func (mt MarshalType) NeedsValidation() bool { + switch mt { + case MarshalTypeNearestDelta2, + MarshalTypeNearestDelta: + return true + default: + // Other types do not need additional validation, + // since they either already contain checksums (e.g. compressed data) + // or they are trivial and cannot be validated (e.g. const or delta const) + return false + } +} + // CheckMarshalType verifies whether the mt is valid. func CheckMarshalType(mt MarshalType) error { if mt < 0 || mt > 6 { diff --git a/lib/storage/block.go b/lib/storage/block.go index 84c7ee6265..6513c4c449 100644 --- a/lib/storage/block.go +++ b/lib/storage/block.go @@ -271,7 +271,7 @@ func (b *Block) UnmarshalData() error { if b.bh.PrecisionBits < 64 { // Recover timestamps order after lossy compression. encoding.EnsureNonDecreasingSequence(b.timestamps, b.bh.MinTimestamp, b.bh.MaxTimestamp) - } else { + } else if b.bh.TimestampsMarshalType.NeedsValidation() { // Ensure timestamps are in the range [MinTimestamp ... MaxTimestamps] and are ordered. if err := checkTimestampsBounds(b.timestamps, b.bh.MinTimestamp, b.bh.MaxTimestamp); err != nil { return err