fix(pymsg): 修复消息长度无上限导致 OOM DoS 漏洞
Python/Go 端 recv 缺失消息大小上限检查,恶意客户端发送 4 字节 超大长度头即可触发 OOM。新增 64 MiB 上限(与 C++ 端 Msg.hpp 对齐),在分配内存前拒绝并断开连接。新增 5 个单元测试覆盖。
This commit is contained in:
1 parent
e248290860
commit
267d572906
3 files changed
+140
No files matched your search
@@ -25,6 +25,8 @@ const (
|
||||
batchSize = 50
|
||||
flushInterval = 2 * time.Second
|
||||
socketTimeout = 5 * time.Second
|
||||
// 消息大小安全上限(64 MiB),与 Python / C++ 端保持一致。
|
||||
maxMsgSize = 64 * 1024 * 1024
|
||||
)
|
||||
|
||||
// Entry 单条日志。
|
||||
@@ -247,6 +249,9 @@ func pymsgCall(payload []byte) ([]byte, error) {
|
||||
return nil, err
|
||||
}
|
||||
respLen := binary.BigEndian.Uint32(header)
|
||||
if respLen > maxMsgSize {
|
||||
return nil, fmt.Errorf("response too large: %d bytes (max %d)", respLen, maxMsgSize)
|
||||
}
|
||||
resp := make([]byte, respLen)
|
||||
if _, err := io.ReadFull(conn, resp); err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in new issue
Block a user