Skip to content

Commit e86190c

Browse files
CopilotPIKACHUIM
andauthored
fix(torrent): address minor review suggestions - safe int cast comment and named constant
Agent-Logs-Url: https://github.com/OpenListTeam/OpenList/sessions/2752452f-b9e2-4f09-a5f0-837ea189aa28 Co-authored-by: PIKACHUIM <[email protected]>
1 parent 4a21d85 commit e86190c

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

internal/offline_download/tool/transfer.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/OpenListTeam/OpenList/v4/internal/task"
1919
"github.com/OpenListTeam/OpenList/v4/internal/task_group"
2020
"github.com/OpenListTeam/OpenList/v4/pkg/http_range"
21+
"github.com/OpenListTeam/OpenList/v4/pkg/torrent"
2122
"github.com/OpenListTeam/OpenList/v4/pkg/utils"
2223
"github.com/OpenListTeam/OpenList/v4/server/common"
2324
"github.com/OpenListTeam/tache"
@@ -379,7 +380,7 @@ func tryRapidUpload189(t *TransferTask, file *os.File, fileSize int64) (model.Ob
379380
}
380381

381382
// 计算整文件 MD5(旧接口只需要 fileMD5)
382-
fileMD5, _, err := _189pc.ComputeSliceMD5sFromReader(file, 10*1024*1024)
383+
fileMD5, _, err := _189pc.ComputeSliceMD5sFromReader(file, torrent.DefaultPieceSize)
383384
if err != nil {
384385
return nil, fmt.Errorf("计算 MD5 失败: %w", err)
385386
}

pkg/torrent/bencode.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ func bencodeDecodeString(r *bytes.Reader) ([]byte, error) {
209209
if length < 0 || length > 100*1024*1024 {
210210
return nil, fmt.Errorf("bencode: string length out of bounds: %d", length)
211211
}
212+
// Safe to convert to int: bounds check above ensures length <= 100MB which fits in int32
212213
data := make([]byte, int(length))
213214
_, err = io.ReadFull(r, data)
214215
if err != nil {

0 commit comments

Comments
 (0)