Skip to content

Commit 28a6163

Browse files
Fix hex2intTable out of range bug
hex2intTable only contains 254 entries why it should be 255. Sending for example Transfer-Encoding: \xff causes an out of range panic. Because fasthttp never uses defer-recover and runs in its own goroutines the user of this package can do nothing to defend against this bug.
1 parent 1d878df commit 28a6163

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

bytesconv.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -311,15 +311,17 @@ func hexCharUpper(c byte) byte {
311311
}
312312

313313
var hex2intTable = func() []byte {
314-
b := make([]byte, 255)
315-
for i := byte(0); i < 255; i++ {
316-
c := byte(0)
317-
if i >= '0' && i <= '9' {
318-
c = 1 + i - '0'
319-
} else if i >= 'a' && i <= 'f' {
320-
c = 1 + i - 'a' + 10
321-
} else if i >= 'A' && i <= 'F' {
322-
c = 1 + i - 'A' + 10
314+
b := make([]byte, 256)
315+
for i := 0; i < 256; i++ {
316+
c := byte(i)
317+
if c >= '0' && c <= '9' {
318+
c = 1 + c - '0'
319+
} else if c >= 'a' && c <= 'f' {
320+
c = 1 + c - 'a' + 10
321+
} else if c >= 'A' && c <= 'F' {
322+
c = 1 + c - 'A' + 10
323+
} else {
324+
c = 0
323325
}
324326
b[i] = c
325327
}

0 commit comments

Comments
 (0)