mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-26 17:46:34 +03:00
Prevent overflow and panic on large HTTP responses (#1351)
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"mime/multipart"
|
||||
"net"
|
||||
"os"
|
||||
@@ -2278,5 +2279,10 @@ func round2(n int) int {
|
||||
x |= x >> 8
|
||||
x |= x >> 16
|
||||
|
||||
// Make sure we don't return 0 due to overflow, even on 32 bit systems
|
||||
if x >= uint32(math.MaxInt32) {
|
||||
return math.MaxInt32
|
||||
}
|
||||
|
||||
return int(x + 1)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -1963,6 +1964,7 @@ func TestRound2(t *testing.T) {
|
||||
testRound2(t, 8, 8)
|
||||
testRound2(t, 9, 16)
|
||||
testRound2(t, 0x10001, 0x20000)
|
||||
testRound2(t, math.MaxInt32-1, math.MaxInt32)
|
||||
}
|
||||
|
||||
func testRound2(t *testing.T, n, expectedRound2 int) {
|
||||
|
||||
Reference in New Issue
Block a user