File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed
Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change 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 {
You can’t perform that action at this time.
0 commit comments