From fc9df8dcf067771c17b9edfb5439e561c5ce8f9e Mon Sep 17 00:00:00 2001 From: zu1k Date: Thu, 20 Oct 2022 16:05:02 +0800 Subject: [PATCH] fix: check wry size before read header --- pkg/qqwry/qqwry.go | 4 ++++ pkg/zxipv6wry/zxipv6wry.go | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/pkg/qqwry/qqwry.go b/pkg/qqwry/qqwry.go index 468e626..9b59001 100644 --- a/pkg/qqwry/qqwry.go +++ b/pkg/qqwry/qqwry.go @@ -45,6 +45,10 @@ func NewQQwry(filePath string) (*QQwry, error) { } } + if len(fileData) < 8 { + log.Fatalln("纯真 IP 库存在错误,请重新下载") + } + header := fileData[0:8] start := binary.LittleEndian.Uint32(header[:4]) end := binary.LittleEndian.Uint32(header[4:]) diff --git a/pkg/zxipv6wry/zxipv6wry.go b/pkg/zxipv6wry/zxipv6wry.go index 2791457..d9650f7 100644 --- a/pkg/zxipv6wry/zxipv6wry.go +++ b/pkg/zxipv6wry/zxipv6wry.go @@ -39,6 +39,10 @@ func NewZXwry(filePath string) (*ZXwry, error) { } } + if len(fileData) < 24 { + log.Fatalln("ZX IPv6数据库存在错误,请重新下载") + } + header := fileData[:24] offLen := header[6] ipLen := header[7]