Skip to content

Commit 637781f

Browse files
committed
Security Fix
1 parent e3f7a08 commit 637781f

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

pkg/message/http.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77
"fmt"
88
"io"
9+
"math"
910
"net/textproto"
1011
"strconv"
1112
"strings"
@@ -202,20 +203,31 @@ func readChunkedBody(reader *bufio.Reader, dst *bytes.Buffer) error {
202203
return nil
203204
}
204205

206+
// Check if chunkSize is within the valid range for int
207+
if chunkSize < 0 {
208+
return fmt.Errorf("negative chunk size: %d", chunkSize)
209+
}
210+
if chunkSize > math.MaxInt {
211+
return fmt.Errorf("chunk size too large for this system: %d", chunkSize)
212+
}
213+
214+
// Now safely convert to int
215+
chunkSizeInt := int(chunkSize)
216+
205217
// Check size constraints
206-
totalSize += int(chunkSize)
218+
totalSize += chunkSizeInt
207219
if totalSize > maxBodySize {
208220
return errors.New("HTTP chunked body too large")
209221
}
210222

211223
// Create small buffer for limited reads
212-
bufSize := int(chunkSize)
224+
bufSize := chunkSizeInt
213225
if bufSize > 8192 {
214226
bufSize = 8192
215227
}
216228

217229
// Read the chunk data in smaller pieces if necessary
218-
remaining := int(chunkSize)
230+
remaining := chunkSizeInt
219231
for remaining > 0 {
220232
readSize := remaining
221233
if readSize > bufSize {

0 commit comments

Comments
 (0)