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

blob: (*Blob).UnmarshalJSON crashes with simple JSON []byte("{}") #3727

Open
odeke-em opened this issue Sep 15, 2024 · 1 comment · May be fixed by #3732
Open

blob: (*Blob).UnmarshalJSON crashes with simple JSON []byte("{}") #3727

odeke-em opened this issue Sep 15, 2024 · 1 comment · May be fixed by #3732
Labels
bug Something isn't working external Issues created by non node team members

Comments

@odeke-em
Copy link

Celestia Node version

1a1286f

OS

darwin

Install tools

No response

Others

No response

Steps to reproduce it

If you run this very simple repro

package test

import (
     "testing"

     "github.com/celestiaorg/celestia-node/blob"
)

func TestBlobUnmarshalRepro(t *testing.T) {
     blob := new(blob.Blob)
     _ = blob.UnmarshalJSON([]byte("{}"))
}

Expected result

No panic

Actual result

$ go test -run=Repro
# github.com/celestiaorg/celestia-node/blob.test
--- FAIL: TestBlobUnmarshalRepro (0.00s)
panic: runtime error: index out of range [0] with length 0 [recovered]
	panic: runtime error: index out of range [0] with length 0

goroutine 12 [running]:
testing.tRunner.func1.2({0x10e8315c0, 0xc000065740})
	/Users/emmanuelodeke/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.0.darwin-amd64/src/testing/testing.go:1632 +0x230
testing.tRunner.func1()
	/Users/emmanuelodeke/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.0.darwin-amd64/src/testing/testing.go:1635 +0x35e
panic({0x10e8315c0?, 0xc000065740?})
	/Users/emmanuelodeke/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.0.darwin-amd64/src/runtime/panic.go:785 +0x132
github.com/celestiaorg/celestia-node/share.Namespace.Version(...)
	/Users/emmanuelodeke/go/src/github.com/celestiaorg/celestia-node/share/namespace.go:61
github.com/celestiaorg/celestia-node/blob.(*Blob).UnmarshalJSON(0xc0005b1f20, {0xc0004e8a98, 0x2, 0x2})
	/Users/emmanuelodeke/go/src/github.com/celestiaorg/celestia-node/blob/blob.go:172 +0x1c5
github.com/celestiaorg/celestia-node/blob_test.TestBlobUnmarshalRepro(0xc0004116c0?)
	/Users/emmanuelodeke/go/src/github.com/celestiaorg/celestia-node/blob/repro_test.go:11 +0x4c
testing.tRunner(0xc0004116c0, 0x10e975e50)
	/Users/emmanuelodeke/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.0.darwin-amd64/src/testing/testing.go:1690 +0xf4
created by testing.(*T).Run in goroutine 1
	/Users/emmanuelodeke/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.0.darwin-amd64/src/testing/testing.go:1743 +0x390
exit status 2
FAIL	github.com/celestiaorg/celestia-node/blob	1.501s

Relevant log output

No response

Is the node "stuck"? Has it stopped syncing?

No response

Notes

To fix it, please check that the namespace is non-empty

diff --git a/blob/blob.go b/blob/blob.go
index 369d464e..3b26e5f1 100644
--- a/blob/blob.go
+++ b/blob/blob.go
@@ -168,6 +168,10 @@ func (b *Blob) UnmarshalJSON(data []byte) error {
 		return err
 	}
 
+	if len(jsonBlob.Namespace) == 0 {
+		return errors.New("expected a non-empty namespace")
+	}
+
 	b.Blob = &blob.Blob{}
 	b.Blob.NamespaceVersion = uint32(jsonBlob.Namespace.Version())
 	b.Blob.NamespaceId = jsonBlob.Namespace.ID()
@odeke-em odeke-em added the bug Something isn't working label Sep 15, 2024
@github-actions github-actions bot added the external Issues created by non node team members label Sep 15, 2024
odeke-em added a commit to orijtech/celestia-node that referenced this issue Sep 16, 2024
This changes adds fuzzers+corpra that found some bugs, along
with tests and reproducers to catch future regressions.

Fixes celestiaorg#3727
Fixes celestiaorg#3728
Fixes celestiaorg#3729
Fixes celestiaorg#3730
Fixes celestiaorg#3731
@odeke-em
Copy link
Author

I have mailed out a PR with the fixes along with the fuzzers per #3732

odeke-em added a commit to orijtech/celestia-node that referenced this issue Sep 16, 2024
This changes adds fuzzers+corpra that found some bugs, along
with tests and reproducers to catch future regressions.

Fixes celestiaorg#3727
Fixes celestiaorg#3728
Fixes celestiaorg#3729
Fixes celestiaorg#3730
Fixes celestiaorg#3731
odeke-em added a commit to orijtech/celestia-node that referenced this issue Sep 16, 2024
This changes adds fuzzers+corpra that found some bugs, along
with tests and reproducers to catch future regressions.

Fixes celestiaorg#3727
Fixes celestiaorg#3728
Fixes celestiaorg#3729
Fixes celestiaorg#3730
Fixes celestiaorg#3731
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working external Issues created by non node team members
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant