Commit dc2490bb authored by zhiqiangxu's avatar zhiqiangxu Committed by GitHub

fix `ReadPreimage` (#11805)

* avoid out of bound for TrackingPreimageOracleReader.ReadPreimage

* use p.GetPreimage
parent 8404e91b
......@@ -49,7 +49,7 @@ func (p *TrackingPreimageOracleReader) ReadPreimage(key [32]byte, offset uint32)
preimage := p.lastPreimage
if key != p.lastPreimageKey {
p.lastPreimageKey = key
data := p.po.GetPreimage(key)
data := p.GetPreimage(key)
// add the length prefix
preimage = make([]byte, 0, 8+len(data))
preimage = binary.BigEndian.AppendUint64(preimage, uint64(len(data)))
......@@ -57,6 +57,9 @@ func (p *TrackingPreimageOracleReader) ReadPreimage(key [32]byte, offset uint32)
p.lastPreimage = preimage
}
p.lastPreimageOffset = offset
if offset > uint32(len(preimage)) {
return
}
datLen = uint32(copy(dat[:], preimage[offset:]))
return
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment