@@ -54,6 +54,9 @@ func (dbr *DiskBufferReader) Read(out []byte) (int, error) {
54
54
55
55
// Will need the difference of the requested bytes and how many are read.
56
56
bytesToRead := int (int64 (outLen ) + dbr .index - dbr .bytesRead )
57
+ if bytesToRead <= 0 || bytesToRead > len (out ) {
58
+ return 0 , fmt .Errorf ("unexpected number of new bytes to read. Expected 0 < n <= %d. Got n=%d" , len (out ), bytesToRead )
59
+ }
57
60
readerBytes := make ([]byte , bytesToRead )
58
61
59
62
// Read the bytes from the reader.
@@ -144,8 +147,11 @@ func (dbr *DiskBufferReader) Seek(offset int64, whence int) (int64, error) {
144
147
trashBytes := make ([]byte , 1024 )
145
148
for {
146
149
_ , err := dbr .Read (trashBytes )
147
- if errors .Is (err , io .EOF ) {
148
- break
150
+ if err != nil {
151
+ if errors .Is (err , io .EOF ) {
152
+ break
153
+ }
154
+ return dbr .index , err
149
155
}
150
156
}
151
157
if dbr .index + offset < 0 {
@@ -161,6 +167,9 @@ func (dbr *DiskBufferReader) Seek(offset int64, whence int) (int64, error) {
161
167
// ReadAt reads len(p) bytes into p starting at offset off in the underlying input source.
162
168
func (dbr * DiskBufferReader ) ReadAt (out []byte , offset int64 ) (int , error ) {
163
169
startIndex , err := dbr .Seek (offset , io .SeekStart )
170
+ if err != nil {
171
+ return 0 , err
172
+ }
164
173
switch {
165
174
case startIndex != offset :
166
175
return 0 , io .EOF
0 commit comments