From c48c0e7da17e8fc06133e431ce7c10e7a3e94f06 Mon Sep 17 00:00:00 2001 From: shi yuhang <52435083+shiyuhang0@users.noreply.github.com> Date: Fri, 5 Jan 2024 16:47:16 +0800 Subject: [PATCH] Fix unsigned int overflow (#1530) --- driver_test.go | 15 +++++++++------ packets.go | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/driver_test.go b/driver_test.go index 6bdb78c78..5934caab6 100644 --- a/driver_test.go +++ b/driver_test.go @@ -388,16 +388,16 @@ func TestCRUD(t *testing.T) { func TestNumbersToAny(t *testing.T) { runTestsParallel(t, dsn, func(dbt *DBTest, tbl string) { dbt.mustExec("CREATE TABLE " + tbl + " (id INT PRIMARY KEY, b BOOL, i8 TINYINT, " + - "i16 SMALLINT, i32 INT, i64 BIGINT, f32 FLOAT, f64 DOUBLE)") - dbt.mustExec("INSERT INTO " + tbl + " VALUES (1, true, 127, 32767, 2147483647, 9223372036854775807, 1.25, 2.5)") + "i16 SMALLINT, i32 INT, i64 BIGINT, f32 FLOAT, f64 DOUBLE, iu32 INT UNSIGNED)") + dbt.mustExec("INSERT INTO " + tbl + " VALUES (1, true, 127, 32767, 2147483647, 9223372036854775807, 1.25, 2.5, 4294967295)") - // Use binaryRows for intarpolateParams=false and textRows for intarpolateParams=true. - rows := dbt.mustQuery("SELECT b, i8, i16, i32, i64, f32, f64 FROM "+tbl+" WHERE id=?", 1) + // Use binaryRows for interpolateParams=false and textRows for interpolateParams=true. + rows := dbt.mustQuery("SELECT b, i8, i16, i32, i64, f32, f64, iu32 FROM "+tbl+" WHERE id=?", 1) if !rows.Next() { dbt.Fatal("no data") } - var b, i8, i16, i32, i64, f32, f64 any - err := rows.Scan(&b, &i8, &i16, &i32, &i64, &f32, &f64) + var b, i8, i16, i32, i64, f32, f64, iu32 any + err := rows.Scan(&b, &i8, &i16, &i32, &i64, &f32, &f64, &iu32) if err != nil { dbt.Fatal(err) } @@ -422,6 +422,9 @@ func TestNumbersToAny(t *testing.T) { if f64.(float64) != 2.5 { dbt.Errorf("f64 != 2.5") } + if iu32.(int64) != 4294967295 { + dbt.Errorf("iu32 != 4294967295") + } }) } diff --git a/packets.go b/packets.go index 49e6bb058..94b46b10f 100644 --- a/packets.go +++ b/packets.go @@ -828,7 +828,7 @@ func (rows *textRows) readRow(dest []driver.Value) error { } case fieldTypeTiny, fieldTypeShort, fieldTypeInt24, fieldTypeYear, fieldTypeLong: - dest[i], err = strconv.ParseInt(string(buf), 10, 32) + dest[i], err = strconv.ParseInt(string(buf), 10, 64) case fieldTypeLongLong: if rows.rs.columns[i].flags&flagUnsigned != 0 {