Potential fix for code scanning alert no. 53: Incorrect conversion between integer types #781
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Potential fix for https://github.com/marle3003/mokapi/security/code-scanning/53
To fix the identified issue, we must ensure that when handling the Avro "int" type and converting from float64/other sources to Go
int, the value fits within both the Avro 32-bit signed integer range (math.MinInt32tomath.MaxInt32) and the Gointrange (though targeting the Avro spec is more important). This is best achieved by adding an explicit range check before the conversion and returning an error if the value is out of bounds. The check should be applied to all code paths where a value is converted tointas part of parsing Avro "int" types.Required adjustments:
schema/avro/schema/parser_json.go, specifically inside theparseTypefunction for"int"type when handlingfloat64.valtoint, usingmath.MinInt32andmath.MaxInt32.mathis already imported.Suggested fixes powered by Copilot Autofix. Review carefully before merging.