FloatTech / ZeroBot-Plugin

基于 ZeroBot 的 OneBot 插件
GNU Affero General Public License v3.0
2.49k stars 2.02k forks source link

[mcfish]合成装备功能,选择鱼竿流程未对输入值进行验证,导致数组越界 #922

Closed vatebur closed 4 months ago

vatebur commented 4 months ago

报错信息

ERRO[0985] [bot] execute handler err: runtime error: index out of range [6] with length 6
goroutine 22443 [running]:
runtime/debug.Stack()
        runtime/debug/stack.go:24 +0x65
github.com/wdvxdr1123/ZeroBot.match.func2.1.1()
        github.com/wdvxdr1123/ZeroBot@v1.7.5-0.20240505070304-562ffeb33dcd/bot.go:253 +0x45
panic({0x103c1a0, 0xc002225f50})
        runtime/panic.go:884 +0x213
github.com/FloatTech/ZeroBot-Plugin/plugin/mcfish.init.3.func4(0xc001f0ab90)
        github.com/FloatTech/ZeroBot-Plugin/plugin/mcfish/pole.go:448 +0x15ed
github.com/wdvxdr1123/ZeroBot.match.func2.1()
        github.com/wdvxdr1123/ZeroBot@v1.7.5-0.20240505070304-562ffeb33dcd/bot.go:256 +0x68
created by github.com/wdvxdr1123/ZeroBot.match.func2
        github.com/wdvxdr1123/ZeroBot@v1.7.5-0.20240505070304-562ffeb33dcd/bot.go:249 +0xaa 

复现演示: 只有0-5号鱼竿时,输入不存在的6号竿,会引起报错。

image

vatebur commented 4 months ago

推测是max值边界有问题,有空再修

POLE.GO:

        max := len(articles)

.....

if first == second || first == third || second == third {
                        ctx.SendChain(message.At(ctx.Event.UserID), message.Text("[0]请输入正确的序号\n", list))
                        continue
                    }
                    if first > max || second > max || third > max {
                        ctx.SendChain(message.At(ctx.Event.UserID), message.Text("[", max, "]请输入正确的序号\n", list))
                        continue
                    }