Skip to content

Commit 33d3ee0

Browse files
committed
make sure reads fit file bounds
1 parent fbb3093 commit 33d3ee0

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,12 @@ function createFile (name, opts) {
106106
}
107107

108108
function read (req) {
109+
const end = req.offset + req.size
110+
if (end > file.size) return req.callback(new Error('Could not satisfy length'))
111+
109112
const io = readers.pop() || allocReader()
110113
io.req = req
111-
io.reader.readAsArrayBuffer(file.slice(req.offset, req.offset + req.size))
114+
io.reader.readAsArrayBuffer(file.slice(req.offset, end))
112115
}
113116

114117
function close (req) {

0 commit comments

Comments
 (0)