Skip to content

Sf 1.11.0 - #7484

Draft
raduchis wants to merge 49 commits into
masterfrom
SF-1.11.0
Draft

Sf 1.11.0#7484
raduchis wants to merge 49 commits into
masterfrom
SF-1.11.0

Conversation

@raduchis

Copy link
Copy Markdown
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 5 days ago

To fix this safely without changing intended functionality, add explicit bounds checks for epochs before converting it to int, using constant limits for the target int width. Since int width is platform-dependent, compute the max/min int constants in a portable way and reject values outside that range (or clamp/fallback). In this function, the least behavior-changing fix is to log and return early when out of range, so no unsafe state update happens.

Concrete edits in process/block/metablock.go (inside epochsFastForward):

  1. Right before mp.nrEpochsChanges = int(epochs), define maxInt and minInt using bit operations:
    • maxInt := int64(^uint(0) >> 1)
    • minInt := -maxInt - 1
  2. Add bound check:
    • if epochs < minInt || epochs > maxInt { ...; return }
  3. Keep existing assignment after successful check.

No new imports or dependencies are needed.

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
@@ -2962,6 +2962,13 @@
 		roundsPerEpochUint = minRoundModulus
 	}
 
+	maxInt := int64(^uint(0) >> 1)
+	minInt := -maxInt - 1
+	if epochs < minInt || epochs > maxInt {
+		log.Error("epochfastforward", "epochs out of int bounds", "epochs", epochs)
+		return
+	}
+
 	mp.nrEpochsChanges = int(epochs)
 	mp.roundsModulus = roundsPerEpochUint
 
EOF
@@ -2962,6 +2962,13 @@
roundsPerEpochUint = minRoundModulus
}

maxInt := int64(^uint(0) >> 1)
minInt := -maxInt - 1
if epochs < minInt || epochs > maxInt {
log.Error("epochfastforward", "epochs out of int bounds", "epochs", 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