From 48f6412cd1b13e5a1bf7de6d87c48c008693edb9 Mon Sep 17 00:00:00 2001 From: Nao Yonashiro Date: Sat, 19 Mar 2022 09:33:16 +0900 Subject: [PATCH] fix: to safe when got unexpected typeptr --- internal/encoder/compiler_norace.go | 2 +- internal/encoder/compiler_race.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/encoder/compiler_norace.go b/internal/encoder/compiler_norace.go index 2576419..706c3db 100644 --- a/internal/encoder/compiler_norace.go +++ b/internal/encoder/compiler_norace.go @@ -4,7 +4,7 @@ package encoder func CompileToGetCodeSet(ctx *RuntimeContext, typeptr uintptr) (*OpcodeSet, error) { - if typeptr > typeAddr.MaxTypeAddr { + if typeptr > typeAddr.MaxTypeAddr || typeptr < typeAddr.BaseTypeAddr { return compileToGetCodeSetSlowPath(typeptr) } index := (typeptr - typeAddr.BaseTypeAddr) >> typeAddr.AddrShift diff --git a/internal/encoder/compiler_race.go b/internal/encoder/compiler_race.go index c744511..2589ef1 100644 --- a/internal/encoder/compiler_race.go +++ b/internal/encoder/compiler_race.go @@ -10,7 +10,7 @@ import ( var setsMu sync.RWMutex func CompileToGetCodeSet(ctx *RuntimeContext, typeptr uintptr) (*OpcodeSet, error) { - if typeptr > typeAddr.MaxTypeAddr { + if typeptr > typeAddr.MaxTypeAddr || typeptr < typeAddr.BaseTypeAddr { return compileToGetCodeSetSlowPath(typeptr) } index := (typeptr - typeAddr.BaseTypeAddr) >> typeAddr.AddrShift