Skip to content

Conversation

@joel-rieke
Copy link
Collaborator

Potential fix for https://github.com/trimble-oss/go-mysql-server/security/code-scanning/270

To resolve the issue, the conversion process should ensure that values are within the bounds of the target type to prevent overflow or incorrect results. This can be achieved by explicitly checking the bounds before performing the conversion. For unsigned integers (uint64), an upper bound check against math.MaxInt64 should be added prior to converting to int64.

The fix involves:

  1. Adding a conditional check for uint64 values to ensure they do not exceed math.MaxInt64 before converting them to int64.
  2. Ensuring other cases that involve conversion to smaller integer types also perform appropriate bounds checks.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…etween integer types

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
if value == float64(int64(value)) {
if value >= float64(math.MinInt64) && value <= float64(math.MaxInt64) {
return t.Convert(int64(value))
if intVal := int64(value); intVal >= math.MinInt8 && intVal <= math.MaxInt8 {

Check failure

Code scanning / CodeQL

Incorrect conversion between integer types High

Incorrect conversion of an unsigned 64-bit integer from
strconv.ParseUint
to a lower bit size type int64 without an upper bound check.
Incorrect conversion of an unsigned 64-bit integer from
strconv.ParseUint
to a lower bit size type int64 without an upper bound check.
Incorrect conversion of an unsigned 64-bit integer from
strconv.ParseUint
to a lower bit size type int64 without an upper bound check.
Incorrect conversion of an unsigned 64-bit integer from
strconv.ParseUint
to a lower bit size type int64 without an upper bound check.

Copilot Autofix

AI 5 months ago

To fix the issue, we need to ensure that the conversion from uint64 to int64 and subsequently to int8 is safe and does not result in unexpected values. This involves:

  1. Adding a stricter bounds check for uint64 values before converting them to int64.
  2. Ensuring that the int64 value is within the range of int8 before performing the conversion.

The changes will be made in the Convert method of the systemBoolType struct in sql/system_booltype.go.

Suggested changeset 1
sql/system_booltype.go

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/sql/system_booltype.go b/sql/system_booltype.go
--- a/sql/system_booltype.go
+++ b/sql/system_booltype.go
@@ -95,3 +95,7 @@
 		if value <= math.MaxInt64 {
-			return t.Convert(int64(value))
+			intVal := int64(value)
+			if intVal >= math.MinInt8 && intVal <= math.MaxInt8 {
+				return int8(intVal), nil
+			}
+			return nil, ErrInvalidSystemVariableValue.New(t.varName, v)
 		}
EOF
@@ -95,3 +95,7 @@
if value <= math.MaxInt64 {
return t.Convert(int64(value))
intVal := int64(value)
if intVal >= math.MinInt8 && intVal <= math.MaxInt8 {
return int8(intVal), nil
}
return nil, ErrInvalidSystemVariableValue.New(t.varName, v)
}
Copilot is powered by AI and may make mistakes. Always verify output.
@joel-rieke joel-rieke marked this pull request as ready for review July 15, 2025 18:29
@joel-rieke joel-rieke merged commit fba2523 into main Jul 15, 2025
8 of 12 checks passed
@joel-rieke joel-rieke deleted the alert-autofix-270 branch July 15, 2025 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants