From 8a9bdc8177d5b4681dd09bb34e7b00170b05e342 Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Wed, 14 Nov 2018 01:59:18 +0800 Subject: [PATCH] Fix ParseUint to support all possible numbers Fixes #461 --- bytesconv.go | 3 ++- bytesconv_32.go | 1 - bytesconv_64.go | 1 - bytesconv_64_test.go | 1 + bytesconv_test.go | 1 + 5 files changed, 4 insertions(+), 3 deletions(-) diff --git a/bytesconv.go b/bytesconv.go index 6292957..9631e9c 100644 --- a/bytesconv.go +++ b/bytesconv.go @@ -183,7 +183,8 @@ func parseUintBuf(b []byte) (int, int, error) { } return v, i, nil } - if i >= maxIntChars { + // Test for overflow. + if v*10 < v { return -1, i, errTooLongInt } v = 10*v + int(k) diff --git a/bytesconv_32.go b/bytesconv_32.go index 1437754..7fd6f5f 100644 --- a/bytesconv_32.go +++ b/bytesconv_32.go @@ -3,6 +3,5 @@ package fasthttp const ( - maxIntChars = 9 maxHexIntChars = 7 ) diff --git a/bytesconv_64.go b/bytesconv_64.go index 09d07ef..edf7309 100644 --- a/bytesconv_64.go +++ b/bytesconv_64.go @@ -3,6 +3,5 @@ package fasthttp const ( - maxIntChars = 18 maxHexIntChars = 15 ) diff --git a/bytesconv_64_test.go b/bytesconv_64_test.go index 52d9e3e..b4165a6 100644 --- a/bytesconv_64_test.go +++ b/bytesconv_64_test.go @@ -38,4 +38,5 @@ func TestParseUintSuccess(t *testing.T) { testParseUintSuccess(t, "123", 123) testParseUintSuccess(t, "1234567890", 1234567890) testParseUintSuccess(t, "123456789012345678", 123456789012345678) + testParseUintSuccess(t, "9223372036854775807", 9223372036854775807) } diff --git a/bytesconv_test.go b/bytesconv_test.go index ea31aab..483bc67 100644 --- a/bytesconv_test.go +++ b/bytesconv_test.go @@ -176,6 +176,7 @@ func TestParseUintError(t *testing.T) { // too big num testParseUintError(t, "12345678901234567890") + testParseUintError(t, "1234567890123456789012") } func TestParseUfloatSuccess(t *testing.T) {