From 021b23a5e773c217db10b91796d87fc544cc06dd Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Tue, 27 Sep 2016 02:13:56 +0900 Subject: [PATCH] audio/wav: Bug fix: return an error when offset is before the start of the data --- audio/wav/decode.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/audio/wav/decode.go b/audio/wav/decode.go index 33a7b5c70..e1cd39fc1 100644 --- a/audio/wav/decode.go +++ b/audio/wav/decode.go @@ -50,8 +50,14 @@ func (s *Stream) Seek(offset int64, whence int) (int64, error) { offset += s.headerSize } n, err := s.src.Seek(offset, whence) + if err != nil { + return 0, err + } + if n-s.headerSize < 0 { + return 0, fmt.Errorf("wav: invalid offset") + } s.remaining = s.dataSize - (n - s.headerSize) - return n, err + return n, nil } // Read is implementation of io.Closer's Close.