Skip to content

ext4: return error instead of panicking on special file inodes#349

Open
vvoland wants to merge 1 commit intodiskfs:masterfrom
vvoland:fix-panic
Open

ext4: return error instead of panicking on special file inodes#349
vvoland wants to merge 1 commit intodiskfs:masterfrom
vvoland:fix-panic

Conversation

@vvoland
Copy link

@vvoland vvoland commented Mar 24, 2026

OpenFile and openFileViaInode panic with a nil pointer dereference when called on character device, block device, FIFO, or socket inodes. These inode types store device major/minor numbers instead of an extent tree, so inode.extents is nil and the call to inode.extents.blocks() crashes.

Add a nil guard that returns a descriptive error before accessing the extent tree.

Before this patch, the test TestOpenFileSpecialFileReturnsError failed with panic:

--- FAIL: TestOpenFileSpecialFileReturnsError (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered, repanicked]
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x57c15c]

goroutine 21 [running]:
testing.tRunner.func1.2({0x605880, 0x814950})
	/usr/lib/go-1.26/src/testing/testing.go:1974 +0x232
testing.tRunner.func1()
	/usr/lib/go-1.26/src/testing/testing.go:1977 +0x349
panic({0x605880?, 0x814950?})
	/usr/lib/go-1.26/src/runtime/panic.go:860 +0x13a
github.com/diskfs/go-diskfs/filesystem/ext4.(*FileSystem).OpenFile(0x341696991a40, {0x6464bf, 0x8}, 0x0)
	/home/pawel/src/go-diskfs/filesystem/ext4/ext4.go:1280 +0x27c
github.com/diskfs/go-diskfs/filesystem/ext4.TestOpenFileSpecialFileReturnsError(0x341696904248)
	/home/pawel/src/go-diskfs/filesystem/ext4/specialfile_test.go:24 +0x185
testing.tRunner(0x341696904248, 0x65e1b0)
	/usr/lib/go-1.26/src/testing/testing.go:2036 +0xea
created by testing.(*T).Run in goroutine 1
	/usr/lib/go-1.26/src/testing/testing.go:2101 +0x4c5
FAIL	github.com/diskfs/go-diskfs/filesystem/ext4	0.011s
FAIL

OpenFile and openFileViaInode panic with a nil pointer dereference when
called on character device, block device, FIFO, or socket inodes. These
inode types store device major/minor numbers instead of an extent tree,
so inode.extents is nil and the call to inode.extents.blocks() crashes.

Add a nil guard that returns a descriptive error before accessing the
extent tree.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant