-
Notifications
You must be signed in to change notification settings - Fork 4.1k
feat!: adapt iavlx to store interfaces #25481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| io "io" | ||
| "os" | ||
| "path/filepath" | ||
| "runtime" |
Check notice
Code scanning / CodeQL
Sensitive package import Note
|
|
||
| root, err := c.root.Resolve() | ||
| if err != nil { | ||
| panic(err) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods Warning
|
|
||
| value, _, err := root.Get(key) | ||
| if err != nil { | ||
| panic(err) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods Warning
| // compute hash and assign node IDs | ||
| var err error | ||
| hash, err = commitTraverse(commitCtx, c.root, 0) | ||
| rootPtr, err = c.store.ResolveRoot(uint32(version)) |
Check failure
Code scanning / CodeQL
Incorrect conversion between integer types High
strconv.ParseInt
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 14 days ago
To solve this issue, we must ensure that when casting from an int64 to a smaller (unsigned) integer type (uint32), we properly verify that the value fits within the representable domain of uint32. That means the value must be in the range [0, math.MaxUint32]. If the value is outside this range, it should be rejected or a safe default should be returned (or an error raised).
The best way to implement this is to add an explicit check on the range of version in CommitTree.GetImmutable. If version < 0 or version > math.MaxUint32, return an error. This should be done just before the call to ResolveRoot(uint32(version)).
Because this is Go, we need to import the standard math package to obtain math.MaxUint32. The changes required are:
- In
iavl/commit_tree.go, in theGetImmutablemethod, add a range check forversion. - If the bounds check fails, return an error indicating the version is invalid or out of range.
- Import
"math"at the top of the file if not already present.
No other files need to be changed, since the conversion only happens in iavl/commit_tree.go.
-
Copy modified line R6 -
Copy modified lines R306-R309 -
Copy modified line R311
| @@ -3,6 +3,7 @@ | ||
| import ( | ||
| "fmt" | ||
| "io" | ||
| "math" | ||
| "sync" | ||
| "sync/atomic" | ||
|
|
||
| @@ -302,8 +303,12 @@ | ||
| } | ||
|
|
||
| func (c *CommitTree) GetImmutable(version int64) (storetypes.CacheKVStore, error) { | ||
| // Check for valid range before converting from int64 to uint32. | ||
| if version < 0 || version > int64(math.MaxUint32) { | ||
| return nil, fmt.Errorf("invalid version (out of uint32 bounds): %d", version) | ||
| } | ||
| var rootPtr *NodePointer | ||
| if version == c.lastCommitId.Version { | ||
| if version == int64(c.lastCommitId.Version) { | ||
| rootPtr = c.root | ||
| } else { | ||
| var err error |
| root, err := tree.root.Resolve() | ||
| if err != nil { | ||
| return nil, err | ||
| panic(err) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods Warning
| value, _, err := root.Get(key) | ||
| if err != nil { | ||
| return nil, err | ||
| panic(err) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods Warning
| newRoot, _, err := setRecursive(tree.root, leafNode, ctx) | ||
| if err != nil { | ||
| return err | ||
| panic(err) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods Warning
| _, newRoot, _, err := removeRecursive(tree.root, key, ctx) | ||
| if err != nil { | ||
| return err | ||
| panic(err) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods Warning
| func (db *CommitMultiTree) GetKVStore(key storetypes.StoreKey) storetypes.KVStore { | ||
| index, ok := db.treesByKey[key] | ||
| if !ok { | ||
| panic(fmt.Sprintf("store not found for key: %s (key type: %T)", key.Name(), key)) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods Warning
| if err != nil { | ||
| return nil, fmt.Errorf("failed to commit trees: %w", err) | ||
| if index >= len(db.trees) { | ||
| panic(fmt.Sprintf("store index %d out of bounds for key %s (trees length: %d)", index, key.Name(), len(db.trees))) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods Warning
| index, ok := t.treesByKey[key] | ||
| if !ok { | ||
| return nil | ||
| panic(fmt.Sprintf("store not found for key: %s (key type: %T)", key.Name(), key)) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods Warning
| } | ||
| return t.trees[idx] | ||
| if index >= len(t.trees) { | ||
| panic(fmt.Sprintf("store index %d out of bounds for key %s (trees length: %d)", index, key.Name(), len(t.trees))) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods Warning
|
|
||
| func (tree *Tree) applyChangesToParent(origRoot, newRoot *NodePointer, updateBatch KVUpdateBatch) error { | ||
| if tree.root != origRoot { | ||
| panic("cannot apply changes: root has changed") |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods Warning
|
|
||
| func (tree *Tree) Write() { | ||
| if tree.parent == nil { | ||
| panic("cannot write: tree is immutable") |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods Warning
| } | ||
| err := tree.parent.applyChangesToParent(tree.origRoot, tree.root, tree.updateBatch) | ||
| if err != nil { | ||
| panic(err) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods Warning
|
🔒 PR closed: unsigned commits detected This pull request contains 13 commit(s) without a verified signature. How to fix:
Docs: https://docs.github.com/authentication/managing-commit-signature-verification Unsigned commits:
|
|
@aaronc your pull request is missing a changelog! |
Description
Closes: #XXXX