Skip to content

PrefixEndBytes() should return when len(prefix) == 0 #3727

Closed
@mossid

Description

@mossid

In https://github.com/cosmos/cosmos-sdk/blob/develop/store/types/utils.go#L61

        if prefix == nil {
		return nil
	}

        //...
	
	for {
		if end[len(end)-1] != byte(255) {
			end[len(end)-1]++
                        break
                }
                //...
        }

In the for loop, we access on the slice without checking the length. When the provided argument has length 0 but not nil([]byte{}), it throws a runtime error index out of range. We have to replace the conditional expression to len(prefix) == 0 from the current prefix == nil.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions