internal/ops: avoid some bounds checks in decode

Signed-off-by: Egon Elbre <egonelbre@gmail.com>
This commit is contained in:
Egon Elbre
2022-07-02 15:37:09 +03:00
committed by Elias Naur
parent f8efc9c2a6
commit e7dd180447
2 changed files with 5 additions and 4 deletions
+2 -1
View File
@@ -163,9 +163,10 @@ const (
)
func (op *ClipOp) Decode(data []byte) {
if OpType(data[0]) != TypeClip {
if len(data) < TypeClipLen || OpType(data[0]) != TypeClip {
panic("invalid op")
}
data = data[:TypeClipLen]
bo := binary.LittleEndian
r := image.Rectangle{
Min: image.Point{
+3 -3
View File
@@ -160,7 +160,7 @@ func (r *Reader) Decode() (EncodedOp, bool) {
}
func (op *opMacroDef) decode(data []byte) {
if OpType(data[0]) != TypeMacro {
if len(data) < TypeMacroLen || OpType(data[0]) != TypeMacro {
panic("invalid op")
}
bo := binary.LittleEndian
@@ -176,11 +176,11 @@ func (op *opMacroDef) decode(data []byte) {
}
func (m *macroOp) decode(data []byte, refs []interface{}) {
if OpType(data[0]) != TypeCall {
if len(data) < TypeCallLen || len(refs) < 1 || OpType(data[0]) != TypeCall {
panic("invalid op")
}
data = data[:TypeCallLen]
bo := binary.LittleEndian
data = data[:TypeCallLen]
*m = macroOp{
ops: refs[0].(*Ops),
start: PC{