Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binary packet complains Arithmetic operation resulted in an overflow #247

Closed
TheSnowfield opened this issue Mar 26, 2024 · 6 comments
Closed
Assignees
Labels
bug Something isn't working confirmed

Comments

@TheSnowfield
Copy link
Contributor

Platform: Allwinner H3(armhf) with 1GB RAM
Lagrange Ver: latest

[2024-03-26 16:58:26.736] [Debug] [ServiceContext] Outgoing SSOFrame: wtlogin.trans_emp
[2024-03-26 16:58:30.376] [Fatal] [SocketContext] Socket Error: Arithmetic operation resulted in an overflow.
[2024-03-26 16:58:30.441] [Fatal] [SocketContext]    at Lagrange.Core.Utility.Binary.BinaryPacket.ReadBytes(Int32 count) in /root/Kagami/Lagrange.Core/Lagrange.Core/Utility/Binary/BinaryPacket.cs:line 242
   at Lagrange.Core.Utility.Binary.BinaryPacket.ReadString(Prefix flag) in /root/Kagami/Lagrange.Core/Lagrange.Core/Utility/Binary/BinaryPacket.cs:line 256
   at Lagrange.Core.Internal.Packets.SsoPacker.Parse(BinaryPacket packet) in /root/Kagami/Lagrange.Core/Lagrange.Core/Internal/Packets/SsoPacker.cs:line 65
   at Lagrange.Core.Internal.Context.PacketContext.DispatchPacket(BinaryPacket packet) in /root/Kagami/Lagrange.Core/Lagrange.Core/Internal/Context/PacketContext.cs:line 91
   at Lagrange.Core.Internal.Context.SocketContext.OnRecvPacket(ReadOnlySpan`1 packet) in /root/Kagami/Lagrange.Core/Lagrange.Core/Internal/Context/SocketContext.cs:line 68
   at Lagrange.Core.Internal.Network.CallbackClientListener.OnRecvPacket(ReadOnlySpan`1 packet) in /root/Kagami/Lagrange.Core/Lagrange.Core/Internal/Network/CallbackClientListener.cs:line 15
   at Lagrange.Core.Internal.Network.ClientListener.ReceiveLoop(SocketSession session, CancellationToken token) in /root/Kagami/Lagrange.Core/Lagrange.Core/Internal/Network/ClientListener.cs:line 139
[2024-03-26 16:58:30.447] [Fatal] [SocketContext] Socket Disconnected, Scheduling Reconnect

@zhanbao2000
Copy link

同样的问题在另一个平台上

版本:https://github.com/KonataDev/Lagrange.Core/actions/runs/8881050412
系统:Ubuntu 20.04 amd64
平台:Lagrange OneBot

trce: Lagrange.Core.BotContext[0]
      [2024-04-30 23:09:00] [ServiceContext] [DEBUG]: Outgoing
SSOFrame: trpc.login.ecdh.EcdhService.SsoKeyExchange
warn: Lagrange.Core.BotContext[0]
      [2024-04-30 23:09:01] [BusinessContext] [WARNING]: Error
while handling msf push: 12
warn: Lagrange.Core.BotContext[0]
      [2024-04-30 23:09:01] [BusinessContext] [WARNING]: Arithm
etic operation resulted in an overflow.
warn: Lagrange.Core.BotContext[0]
      [2024-04-30 23:09:01] [BusinessContext] [WARNING]:    at
Lagrange.Core.Utility.Binary.BinaryPacket.ReadBytes(Int32 count
)
         at Lagrange.Core.Utility.Binary.BinaryPacket.ReadBytes
(Prefix flag)
         at Lagrange.Core.Internal.Context.ServiceContext.Resol
veEventByPacket(SsoPacket packet)
         at Lagrange.Core.Internal.Context.BusinessContext.Hand
leServerPacket(SsoPacket packet)
trce: Lagrange.Core.BotContext[0]
      [2024-04-30 23:09:01] [BusinessContext] [DEBUG]:
trce: Lagrange.Core.BotContext[0]
      [2024-04-30 23:09:10] [ServiceContext] [DEBUG]: Outgoing
SSOFrame: Heartbeat.Alive
trce: Lagrange.Core.BotContext[0]
      [2024-04-30 23:09:20] [ServiceContext] [DEBUG]: Outgoing
SSOFrame: Heartbeat.Alive
trce: Lagrange.Core.BotContext[0]
      [2024-04-30 23:09:30] [ServiceContext] [DEBUG]: Outgoing
SSOFrame: Heartbeat.Alive
(以下重复)

@synodriver
Copy link

使用最新的docker镜像部署确认可以复现

@zhanbao2000
Copy link

尝试删除了 keystore.json 从而重新登录,问题依旧

trce: Lagrange.Core.BotContext[0]
      [2024-05-03 00:01:57] [ServiceContext] [DEBUG]: Outgoing SSOFrame: trpc.login.ecdh.EcdhService.SsoKeyExchange
trce: Lagrange.Core.BotContext[0]
      [2024-05-03 00:01:57] [ServiceContext] [DEBUG]: Incoming SSOFrame: trpc.login.ecdh.EcdhService.SsoKeyExchange
info: Lagrange.Core.BotContext[0]
      [2024-05-03 00:01:57] [WtExchangeLogic] [INFORMATION]: Key Exchange successfully!
info: Lagrange.Core.BotContext[0]
      [2024-05-03 00:01:57] [WtExchangeLogic] [INFORMATION]: Trying to Login by Password...
trce: Lagrange.Core.BotContext[0]
      [2024-05-03 00:01:58] [ServiceContext] [DEBUG]: Outgoing SSOFrame: trpc.login.ecdh.EcdhService.SsoNTLoginPasswordLogin
trce: Lagrange.Core.BotContext[0]
      [2024-05-03 00:01:58] [ServiceContext] [DEBUG]: Incoming SSOFrame: trpc.login.ecdh.EcdhService.SsoNTLoginPasswordLogin
info: Lagrange.Core.BotContext[0]
      [2024-05-03 00:01:58] [WtExchangeLogic] [INFORMATION]: Login Success
trce: Lagrange.Core.BotContext[0]
      [2024-05-03 00:01:58] [ServiceContext] [DEBUG]: Outgoing SSOFrame: trpc.qq_new_tech.status_svc.StatusService.Register
warn: Lagrange.Core.BotContext[0]
      [2024-05-03 00:01:58] [BusinessContext] [WARNING]: Error when processing the event: Lagrange.Core.Internal.Event.System.StatusRegisterEvent
warn: Lagrange.Core.BotContext[0]
      [2024-05-03 00:01:58] [BusinessContext] [WARNING]: Packet 'trpc.qq_new_tech.status_svc.StatusService.Register' returns -10003 with seq: 5695743, extra: 身份验证失败,请你重新登录 (s21)
warn: Lagrange.Core.BotContext[0]
      [2024-05-03 00:01:58] [BusinessContext] [WARNING]:    at Lagrange.Core.Internal.Context.BusinessContext.SendEvent(ProtocolEvent event)
trce: Lagrange.Core.BotContext[0]
      [2024-05-03 00:02:06] [ServiceContext] [DEBUG]: Outgoing SSOFrame: Heartbeat.Alive
warn: Lagrange.Core.BotContext[0]
      [2024-05-03 00:02:07] [BusinessContext] [WARNING]: Error while handling msf push: 12 Heartbeat.Alive
warn: Lagrange.Core.BotContext[0]
      [2024-05-03 00:02:07] [BusinessContext] [WARNING]: Arithmetic operation resulted in an overflow.
warn: Lagrange.Core.BotContext[0]
      [2024-05-03 00:02:07] [BusinessContext] [WARNING]:    at Lagrange.Core.Utility.Binary.BinaryPacket.ReadBytes(Int32 count)
         at Lagrange.Core.Utility.Binary.BinaryPacket.ReadBytes(Prefix flag)
         at Lagrange.Core.Internal.Context.ServiceContext.ResolveEventByPacket(SsoPacket packet)
         at Lagrange.Core.Internal.Context.BusinessContext.HandleServerPacket(SsoPacket packet)
trce: Lagrange.Core.BotContext[0]
      [2024-05-03 00:02:07] [BusinessContext] [DEBUG]: 
trce: Lagrange.Core.BotContext[0]
      [2024-05-03 00:02:16] [ServiceContext] [DEBUG]: Outgoing SSOFrame: Heartbeat.Alive
warn: Lagrange.Core.BotContext[0]
      [2024-05-03 00:02:17] [BusinessContext] [WARNING]: Error while handling msf push: 12 Heartbeat.Alive
warn: Lagrange.Core.BotContext[0]
      [2024-05-03 00:02:17] [BusinessContext] [WARNING]: Arithmetic operation resulted in an overflow.
warn: Lagrange.Core.BotContext[0]
      [2024-05-03 00:02:17] [BusinessContext] [WARNING]:    at Lagrange.Core.Utility.Binary.BinaryPacket.ReadBytes(Int32 count)
         at Lagrange.Core.Utility.Binary.BinaryPacket.ReadBytes(Prefix flag)
         at Lagrange.Core.Internal.Context.ServiceContext.ResolveEventByPacket(SsoPacket packet)
         at Lagrange.Core.Internal.Context.BusinessContext.HandleServerPacket(SsoPacket packet)
trce: Lagrange.Core.BotContext[0]
      [2024-05-03 00:02:17] [BusinessContext] [DEBUG]:
(以下重复)

尝试在 appsettings.json 中删除 Password 字段,从而使用扫码登陆,能正常登录并收发消息

再次删除 keystore.json,尝试使用密码登录,问题依旧,打印日志与上述一致

@TheSnowfield
Copy link
Contributor Author

TheSnowfield commented May 4, 2024

根據我的經驗,這個問題很有可能是因爲在arm設備上性能不足產生的邏輯問題,
可以往這個方向去排查。
參考: KonataDev/Konata.Core#121

@Executor-Cheng
Copy link
Collaborator

调查结论如下:
BinaryPacket 实现里边的 Read 相关方法并没有检查 eof 的情况
PacketContext.DispatchPacket 中 L91 返回的 SsoPacket.Payload 里边实际上装的是一个空的 byte[]
稍后调用 Collection.Business.HandleServerPacket(sso) 时, 其中 var events = Collection.Service.ResolveEventByPacket(packet) 里边调用到 var payload = packet.Payload.ReadBytes(Prefix.Uint32 | Prefix.WithPrefix); 时, 由于 BinaryPacket.ReadUint 对空的 byte[] 进行读取会返回0, 导致 BinaryPacket.ReadBytes 试图创建一个长度为 -4 的数组, 引发 System.OverflowException 异常

cc @Linwenxuan05 @TheSnowfield

@TheSnowfield TheSnowfield added the bug Something isn't working label May 5, 2024
@synodriver
Copy link

删除keystore可能可以解决之(有待更多验证)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working confirmed
Projects
None yet
Development

No branches or pull requests

5 participants