k6 icon indicating copy to clipboard operation
k6 copied to clipboard

Potential fix for code scanning alert no. 91: Incorrect conversion between integer types

Open mstoykov opened this issue 5 months ago • 0 comments

Potential fix for https://github.com/grafana/k6/security/code-scanning/91

To address the issue, we need to ensure that the conversion from float64 to int is safe and does not result in unexpected values. This can be achieved by:

  1. Adding bounds checks to ensure the float64 value is within the valid range for the int type.
  2. Returning an error or a default value if the bounds are violated.

The fix involves modifying the count function in internal/js/modules/k6/browser/common/element_handle.go to include bounds checks using constants from the math package (math.MinInt32 and math.MaxInt32 for 32-bit systems, or equivalent for 64-bit systems).


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

mstoykov avatar Jun 13 '25 13:06 mstoykov