Skip to content

Commit

Permalink
refactor: improve edge case handling for recursion limits (#22988)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex | Skip <[email protected]>
  • Loading branch information
haiyizxx and Alex | Skip authored Jan 6, 2025
1 parent 884a7a5 commit 93282e1
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i

### Improvements

* (codec) [#22988](https://github.com/cosmos/cosmos-sdk/pull/22988) Improve edge case handling for recursion limits.

### Bug Fixes

* (query) [23002](https://github.com/cosmos/cosmos-sdk/pull/23002) Fix collection filtered pagination.
Expand Down
4 changes: 2 additions & 2 deletions codec/types/interface_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,10 @@ func (r statefulUnpacker) cloneForRecursion() *statefulUnpacker {
// UnpackAny deserializes a protobuf Any message into the provided interface, ensuring the interface is a pointer.
// It applies stateful constraints such as max depth and call limits, and unpacks interfaces if required.
func (r *statefulUnpacker) UnpackAny(any *Any, iface interface{}) error {
if r.maxDepth == 0 {
if r.maxDepth <= 0 {
return errors.New("max depth exceeded")
}
if r.maxCalls.count == 0 {
if r.maxCalls.count <= 0 {
return errors.New("call limit exceeded")
}
// here we gracefully handle the case in which `any` itself is `nil`, which may occur in message decoding
Expand Down
2 changes: 1 addition & 1 deletion codec/unknownproto/unknown_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func doRejectUnknownFields(
if len(bz) == 0 {
return hasUnknownNonCriticals, nil
}
if recursionLimit == 0 {
if recursionLimit <= 0 {
return false, errors.New("recursion limit reached")
}

Expand Down
2 changes: 1 addition & 1 deletion x/tx/decode/unknown.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func doRejectUnknownFields(
if len(bz) == 0 {
return hasUnknownNonCriticals, nil
}
if recursionLimit == 0 {
if recursionLimit <= 0 {
return false, errors.New("recursion limit reached")
}

Expand Down

0 comments on commit 93282e1

Please sign in to comment.