Skip to content

Conversation

@raduchis
Copy link
Contributor

Reasoning behind the pull request

Proposed changes

Testing procedure

Pre-requisites

Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:

  • was the PR targeted to the correct branch?
  • if this is a larger feature that probably needs more than one PR, is there a feat branch created?
  • if this is a feat branch merging, do all satellite projects have a proper tag inside go.mod?

roundsPerEpochUint = minRoundModulus
}

mp.nrEpochsChanges = int(epochs)

Check failure

Code scanning / CodeQL

Incorrect conversion between integer types High

Incorrect conversion of a signed 64-bit integer from
strconv.ParseInt
to a lower bit size type int without an upper bound check.

Copilot Autofix

AI about 1 month ago

The correct way to fix this is to ensure that the int64 value (epochs) is within the representable range for the type we're converting to (int) before the conversion takes place. This can be done by explicitly checking that epochs is between math.MinInt and math.MaxInt. If the bounds are violated, the application should either reject the input (log an error and do not apply the mutation), or fallback to a default safe value/behavior. To implement this, import the math package if it is not already present (it is), and insert a conditional check before assigning to mp.nrEpochsChanges. This check should act as a guard, such that if epochs is out of bounds, mp.nrEpochsChanges is not updated and a warning or error is logged.

Suggested changeset 1
process/block/metablock.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/process/block/metablock.go b/process/block/metablock.go
--- a/process/block/metablock.go
+++ b/process/block/metablock.go
@@ -2821,6 +2821,11 @@
 		roundsPerEpochUint = minRoundModulus
 	}
 
+	// Ensure epochs can safely fit into int before assignment
+	if epochs < int64(math.MinInt) || epochs > int64(math.MaxInt) {
+		log.Error("epochfastforward", "epochs value out of int bounds", epochs)
+		return
+	}
 	mp.nrEpochsChanges = int(epochs)
 	mp.roundsModulus = roundsPerEpochUint
 
EOF
@@ -2821,6 +2821,11 @@
roundsPerEpochUint = minRoundModulus
}

// Ensure epochs can safely fit into int before assignment
if epochs < int64(math.MinInt) || epochs > int64(math.MaxInt) {
log.Error("epochfastforward", "epochs value out of int bounds", epochs)
return
}
mp.nrEpochsChanges = int(epochs)
mp.roundsModulus = roundsPerEpochUint

Copilot is powered by AI and may make mistakes. Always verify output.
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.

4 participants