Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Fix: panic when childer is nil #127

Merged
merged 2 commits into from
Oct 12, 2022
Merged

Fix: panic when childer is nil #127

merged 2 commits into from
Oct 12, 2022

Conversation

ajnavarro
Copy link
Member

Context: ipfs/kubo#9063

When stressing go-mfs over fuzz testing, we can cause nil pointer exceptions like:

testing.go:1349: panic: runtime error: invalid memory address or nil pointer dereference
            goroutine 6908 [running]:
            runtime/debug.Stack()
                /usr/local/go/src/runtime/debug/stack.go:24 +0x90
            testing.tRunner.func1()
                /usr/local/go/src/testing/testing.go:1349 +0x1f2
            panic({0xa6ec60, 0xefe2e0})
                /usr/local/go/src/runtime/panic.go:838 +0x207
            github.com/ipfs/go-unixfs/hamt.(*childer).has(...)
                /home/ajnavarro/go/pkg/mod/github.com/ipfs/go-unixfs@v0.4.0/hamt/hamt.go:886
            github.com/ipfs/go-unixfs/hamt.(*Shard).swapValue(0xc0029067e0, {0xbc1440, 0xc000024088}, 0xc0000e5348, {0xc00014e001, 0xf10}, 0xc002462420)
                /home/ajnavarro/go/pkg/mod/github.com/ipfs/go-unixfs@v0.4.0/hamt/hamt.go:623 +0xa3
            github.com/ipfs/go-unixfs/hamt.(*Shard).swapValue(0xc002906770, {0xbc1440, 0xc000024088}, 0xc0000e5348, {0xc00014e001, 0xf10}, 0xc002462420)
                /home/ajnavarro/go/pkg/mod/github.com/ipfs/go-unixfs@v0.4.0/hamt/hamt.go:689 +0x745
            github.com/ipfs/go-unixfs/hamt.(*Shard).SetLink(0xc002906770, {0xbc1440, 0xc000024088}, {0xc00014e001, 0xf10}, 0xc001fbaf90)
                /home/ajnavarro/go/pkg/mod/github.com/ipfs/go-unixfs@v0.4.0/hamt/hamt.go:248 +0x1f7
            github.com/ipfs/go-unixfs/io.(*BasicDirectory).switchToSharding(0xc00007ca60, {0xbc1440, 0xc000024088})
                /home/ajnavarro/go/pkg/mod/github.com/ipfs/go-unixfs@v0.4.0/io/directory.go:337 +0x2db
            github.com/ipfs/go-unixfs/io.(*DynamicDirectory).AddChild(0xc0002efdd0, {0xbc1440, 0xc000024088}, {0xc0044f9629, 0x2}, {0xbc32b8, 0xc0027f13e0})
                /home/ajnavarro/go/pkg/mod/github.com/ipfs/go-unixfs@v0.4.0/io/directory.go:569 +0x113
            github.com/ipfs/go-mfs.(*Directory).Mkdir(0xc0001a4800, {0xc0044f9629, 0x2})
                /home/ajnavarro/workspace/go-mfs/dir.go:316 +0x516
            github.com/ipfs/go-mfs.Mkdir(0xc0002efdb0, {0xc0044f9629, 0x2}, {0x0?, 0x0?, {0x0?, 0x0?}})
                /home/ajnavarro/workspace/go-mfs/ops.go:175 +0x31f
            github.com/ipfs/go-mfs.FuzzMkdirAndWriteConcurrently.func1(0xc000102680, 0xd0?, 0x57?, {0xc0044f9629, 0x2}, {0x0, 0x0}, {0xc0044f9650, 0x1, 0x8})
                /home/ajnavarro/workspace/go-mfs/mfs_test.go:1540 +0x8d
            reflect.Value.call({0xa75ae0?, 0xc0002efde0?, 0x13?}, {0xaf8ffc, 0x4}, {0xc002548a80, 0x6, 0x8?})
                /usr/local/go/src/reflect/value.go:556 +0x845
            reflect.Value.Call({0xa75ae0?, 0xc0002efde0?, 0x514?}, {0xc002548a80, 0x6, 0x8})
                /usr/local/go/src/reflect/value.go:339 +0xbf
            testing.(*F).Fuzz.func1.1(0x0?)
                /usr/local/go/src/testing/fuzz.go:337 +0x231
            testing.tRunner(0xc000102680, 0xc0000d9290)
                /usr/local/go/src/testing/testing.go:1439 +0x102
            created by testing.(*F).Fuzz.func1
                /usr/local/go/src/testing/fuzz.go:324 +0x5b8

This PR patches that problem.

I need some experienced eyes to check that what I did is 100% correct.

Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
hamt/hamt.go Outdated Show resolved Hide resolved
Co-authored-by: Gus Eggert <gus@gus.dev>
@guseggert guseggert merged commit fede2ed into master Oct 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants