From 283ef3219686f720656787e0d50af1dd300e4401 Mon Sep 17 00:00:00 2001 From: Kashiwa <13825170+ksw2000@users.noreply.github.com> Date: Thu, 20 Feb 2025 19:26:35 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20Fix:=20genericParseType=20parsin?= =?UTF-8?q?g=20large=20uint=20leads=20to=20overflow=20(#3315)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🩹 Fix: genericParseType parsing large uint leads to overflow * ♻️ Refactor: use strconv.FormatUint instead of fmt.Sprintf --- ctx_test.go | 4 ++++ helpers.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ctx_test.go b/ctx_test.go index af308866..082b0d44 100644 --- a/ctx_test.go +++ b/ctx_test.go @@ -5522,6 +5522,10 @@ func Test_GenericParseTypeUints(t *testing.T) { value: uint(4), str: "4", }, + { + value: ^uint(0), + str: strconv.FormatUint(uint64(^uint(0)), 10), + }, } for _, test := range uints { diff --git a/helpers.go b/helpers.go index a400be0d..7e9e202c 100644 --- a/helpers.go +++ b/helpers.go @@ -796,7 +796,7 @@ func genericParseType[V GenericType](str string, v V, defaultValue ...V) V { case int64: return genericParseInt[V](str, 64, func(i int64) V { return assertValueType[V, int64](i) }, defaultValue...) case uint: - return genericParseUint[V](str, 32, func(i uint64) V { return assertValueType[V, uint](uint(i)) }, defaultValue...) + return genericParseUint[V](str, 0, func(i uint64) V { return assertValueType[V, uint](uint(i)) }, defaultValue...) case uint8: return genericParseUint[V](str, 8, func(i uint64) V { return assertValueType[V, uint8](uint8(i)) }, defaultValue...) case uint16: