修复下载分片还没全部到齐,GetDownloadPath 就判断开始解密导致的误报Error

This commit is contained in:
f1ynng8
2026-06-21 16:44:34 +08:00
parent 6b29201cc4
commit 9a6533bab1
3 changed files with 22 additions and 1 deletions
+3
View File
@@ -52,6 +52,9 @@ func HandleProtobufMsg(payload map[string]interface{}) ([]byte, error) {
msg := &wxproto.WxRecvMsg{}
err := proto.Unmarshal(rawBytes, msg)
if err != nil {
if strings.Contains(err.Error(), "cannot parse invalid wire-format data") {
return nil, nil
}
return nil, fmt.Errorf("protobuf unmarshal failed: %w", err)
}
+8 -1
View File
@@ -162,7 +162,14 @@ func SilkToMp3(silkBytes []byte) ([]byte, error) {
}
func GetFilePath(data []byte, key []byte) (string, error) {
block, _ := aes.NewCipher(key)
block, err := aes.NewCipher(key)
if err != nil {
return "", err
}
if len(data) == 0 || len(data)%block.BlockSize() != 0 {
return "", fmt.Errorf("invalid encrypted data length: %d, block_size: %d", len(data), block.BlockSize())
}
decrypted := make([]byte, len(data))
bs := block.BlockSize()
for i := 0; i < len(data); i += bs {
+11
View File
@@ -2,6 +2,7 @@ package main
import (
"context"
"crypto/aes"
"encoding/hex"
"encoding/json"
"encoding/xml"
@@ -334,6 +335,16 @@ func GetDownloadPath(cdnUrl, aesKeyStr string) (string, error) {
// 数据接收完成,尝试解密
if len(downloadReq.Media) > 0 {
if len(downloadReq.Media)%aes.BlockSize != 0 {
Info("文件数据仍未对齐 AES 块,继续等待", "url", cdnUrl, "times", i, "media_len", len(downloadReq.Media), "block_size", aes.BlockSize)
if i < 9 {
time.Sleep(2 * time.Second)
continue
}
userID2FileMsgMap.Delete(cdnUrl)
return "", fmt.Errorf("文件数据长度不是 AES 块大小倍数: media_len=%d block_size=%d", len(downloadReq.Media), aes.BlockSize)
}
aesKey, err := hex.DecodeString(aesKeyStr)
if err != nil {
Error("AES key 解码失败", "err", err)