From 35f260bbd9f8f85a332763bb32e6a8711409430e Mon Sep 17 00:00:00 2001 From: Alexander Klauer Date: Sat, 4 Feb 2023 19:33:42 +0100 Subject: [PATCH] Fix overflow on 32-bit archs (#98) * Fix overflow on 32-bit archs packFormatReader uses an uint for its option size, so maxDecuplable must not overflow uint. * Properly format integer value as string On architectures where int is narrower than int64, integer values would be formatted incorrectly when converted to string with strconv.Itoa. Using strconv.FormatInt fixes this. --- lib/stringlib/packformatreader.go | 2 +- runtime/value.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/stringlib/packformatreader.go b/lib/stringlib/packformatreader.go index 15383ab7..7feef92e 100644 --- a/lib/stringlib/packformatreader.go +++ b/lib/stringlib/packformatreader.go @@ -39,7 +39,7 @@ func (p *packFormatReader) smallOptSize(defaultSize uint) (ok bool) { return } -const maxDecuplable = math.MaxUint64 / 10 +const maxDecuplable = math.MaxUint / 10 func (p *packFormatReader) getOptSize() bool { var ( diff --git a/runtime/value.go b/runtime/value.go index 92f842bf..25f49642 100644 --- a/runtime/value.go +++ b/runtime/value.go @@ -303,7 +303,7 @@ func (v Value) ToString() (string, bool) { } switch x := v.iface.(type) { case int64: - return strconv.Itoa(int(v.AsInt())), true + return strconv.FormatInt(v.AsInt(), 10), true case float64: return strconv.FormatFloat(v.AsFloat(), 'g', -1, 64), true case bool: