do not read outside the bounds of the buffer

master
Dominic Tarr 10 years ago
parent 76ce046de9
commit 490e48499d

@ -9,8 +9,13 @@ function read(buf, offset) {
, shift = 0 , shift = 0
, counter = offset , counter = offset
, b , b
, l = buf.length
do { do {
if(counter >= l) {
read.bytesRead = 0
return undefined
}
b = buf[counter++] b = buf[counter++]
res += shift < 28 res += shift < 28
? (b & REST) << shift ? (b & REST) << shift
@ -18,12 +23,7 @@ function read(buf, offset) {
shift += 7 shift += 7
} while (b >= MSB) } while (b >= MSB)
if(b === undefined) { read.bytesRead = counter - offset
read.bytesRead = 0
res = undefined
}
else
read.bytesRead = counter - offset
return res return res
} }

Loading…
Cancel
Save