Skip to content
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

fix(pkg/proof): reject negative indices in QueryTxInclusionProof (backport #3141) #3161

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions pkg/proof/proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package proof_test

import (
"bytes"
"strings"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
tmrand "github.com/tendermint/tendermint/libs/rand"

"github.com/celestiaorg/celestia-app/app"
Expand Down Expand Up @@ -221,3 +224,21 @@ func TestNewShareInclusionProof(t *testing.T) {
})
}
}

// Ensure that we reject negative index values and avoid overflows.
// https://github.com/celestiaorg/celestia-app/issues/3140
func TestQueryTxInclusionProofRejectsNegativeValues(t *testing.T) {
path := []string{"-2"}
req := abci.RequestQuery{Data: []byte{}}
ctx := sdk.Context{}
rawProof, err := proof.QueryTxInclusionProof(ctx, path, req)
if err == nil {
t.Fatal("expected a non-nil error")
}
if !strings.Contains(err.Error(), "negative") {
t.Fatalf("The error should reject negative values and report such, but did not\n\tGot: %v", err)
}
if len(rawProof) != 0 {
t.Fatal("no rawProof expected")
}
}
3 changes: 3 additions & 0 deletions pkg/proof/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ func QueryTxInclusionProof(_ sdk.Context, path []string, req abci.RequestQuery)
if err != nil {
return nil, err
}
if index < 0 {
return nil, fmt.Errorf("path[0] element: %q produced a negative value: %d", path[0], index)
evan-forbes marked this conversation as resolved.
Show resolved Hide resolved
}

// unmarshal the block data that is passed from the ABCI client
pbb := new(tmproto.Block)
Expand Down
Loading