Skip to content

Commit

Permalink
Support large value offset in memStore
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Aug 22, 2017
1 parent 0a51469 commit bc5b108
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/opFns.js
Original file line number Diff line number Diff line change
Expand Up @@ -842,13 +842,17 @@ function memStore (runState, offset, val, valOffset, length, skipSubMem) {
length = length.toNumber()

// Limit to the length of `val` (including the offset)
var valLength = BN.min(valOffset.addn(length), new BN(val.length))

// Limit to the length of `val` or the requested length
valLength = Math.min(valLength, length)
// NOTE: toNumber() is safe here as it will at most as big as val.length
var valLength
if (valOffset.gten(val.length)) {
valLength = 0
} else {
// NOTE: valOffset should be toNumber safe here
valLength = Math.min(val.length - valOffset.toNumber(), length)
}

// NOTE: cheat here a bit, if `valOffset` is out of range, just resort to copying zeroes
if (valOffset.bitLength() <= 53) {
if (valLength > 0 && valOffset.bitLength() <= 53) {
valOffset = valOffset.toNumber()

// read max possible from the value
Expand Down

0 comments on commit bc5b108

Please sign in to comment.