Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unsigned int overflow #1530

Merged
merged 3 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 9 additions & 6 deletions driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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")
}
})
}

Expand Down
2 changes: 1 addition & 1 deletion packets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down