Package: golang-1.24
Version: 1.24.4-3
Severity: grave
X-Debbugs-Cc: [email protected]
fs.ReadDir silently fails to read directories fully. As no error shows
up anywhere, this is silent data corruption, hence grave.
Go test code:
| package main
|
| import (
| "fmt"
| "io/fs"
| "os"
| )
|
| func main() {
| fsys := os.DirFS(os.Args[1])
| entries, _ := fs.ReadDir(fsys, ".")
| count := 0
| for _, entry := range entries {
| info, _ := entry.Info()
| fmt.Println(info.Name(), info.IsDir())
| count += 1
| }
| fmt.Println("found without '.' and '..':", count)
| }
C test code:
| #include <sys/types.h>
| #include <dirent.h>
| #include <stdio.h>
|
| int main(int argc, char *argv[]) {
| DIR* dirp = opendir(argv[1]);
| struct dirent *dp;
| int count = 0;
|
| while (dirp) {
| if ((dp = readdir(dirp)) != NULL) {
| printf("%llu %llu %u %s\n", (long long unsigned)dp->d_ino, (long long
unsigned)dp->d_off, dp->d_type, dp->d_name);
| count++;
| }
| else
| break;
| }
| printf("found %d entries\n", count);
|
| return 0;
| }
If I use them on the same directory, which is implemented via FUSE, the
Go test ends with:
| found without '.' and '..': 46
The C test however shows many more:
| found 65 entries
strace on the Go test shows:
| getdents64(3, 0xc0000be000 /* 48 entries */, 8192) = 1520
| getdents64(3, 0xc0000be000 /* 17 entries */, 8192) = 544
| getdents64(3, 0xc0000be000 /* 0 entries */, 8192) = 0
Aka it find all entries from the first getdents64 call (46 plus "." and
".."), but then fails there somewhere without signaling the caller.
No warning about silent corruption is given in
https://pkg.go.dev/io/fs#ReadDir.
I would assume the underlying cause is the filesystem returning
DT_UNKNOWN as type for "." and "..", which it is allowed to do in all
cases.
-- System Information:
Debian Release: forky/sid
APT prefers testing
APT policy: (700, 'testing'), (500, 'unstable-debug'), (500,
'stable-updates'), (500, 'oldstable-updates'), (500, 'unstable'), (500,
'stable'), (500, 'oldstable'), (1, 'experimental')
Architecture: amd64 (x86_64)
Kernel: Linux 6.16.5+deb14-amd64 (SMP w/16 CPU threads; PREEMPT)
Locale: LANG=de_DE.UTF-8, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8),
LANGUAGE=en_US:en
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
Versions of packages golang-1.24 depends on:
ii golang-1.24-doc 1.24.4-3
ii golang-1.24-go 1.24.4-3
ii golang-1.24-src 1.24.4-3
golang-1.24 recommends no packages.
golang-1.24 suggests no packages.
-- no debconf information