refactor: improve edge case handling for recursion limits (#22988)

Co-authored-by: Alex | Skip <alex@skip.money>
This commit is contained in:
haiyizxx 2025-01-06 03:26:46 -05:00 committed by GitHub
parent 884a7a51c3
commit 93282e101d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 6 additions and 4 deletions

View File

@ -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.

View File

@ -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

View File

@ -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")
}

View File

@ -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")
}