gastownhall/beads · error

directory size overflows int64 at %s

Error message

directory size overflows int64 at %s

What it means

While summing file sizes into an int64, MeasureDirectorySize checks each file before adding: a negative size or one that would push the running total past math.MaxInt64 aborts the measurement. This protects the caller from a silent integer overflow producing a bogus (possibly negative) directory size. It fires only when the tree contains files with nonsensical sizes or a total exceeding ~8 exabytes.

Source

Thrown at internal/storage/directory_size.go:57

	var size int64
	err := walk(root, func(path string, info os.FileInfo, walkErr error) error {
		if err := ctx.Err(); err != nil {
			return err
		}
		if walkErr != nil {
			if path != root && errors.Is(walkErr, fs.ErrNotExist) {
				return nil
			}
			return walkErr
		}
		if info == nil {
			return fmt.Errorf("walk returned no file information for %s", path)
		}
		if info.IsDir() {
			return nil
		}
		if info.Size() < 0 || info.Size() > math.MaxInt64-size {
			return fmt.Errorf("directory size overflows int64 at %s", path)
		}
		size += info.Size()
		return nil
	})
	if err != nil {
		return 0, err
	}
	return size, nil
}

View on GitHub (pinned to 71377f2769)

Solutions

  1. Identify the path named in the error and inspect its reported size (ls -l / stat); replace or repair the file if its metadata is corrupt.
  2. If one file reports a negative size, check the filesystem/driver; on network or FUSE mounts, remount or update the filesystem driver.
  3. If the total genuinely exceeds int64, split the measurement into multiple roots or track the size as big.Int / uint128 instead of int64.
  4. Exclude pathological files from the measured tree (e.g. move them out or filter them) if they are not part of the live data you need to size.

Example fix

// before: trusting one int64 total for an unbounded tree
size += info.Size()
// after: guard per file (as the library does) or pre-check the biggest file
if info.Size() < 0 || info.Size() > math.MaxInt64-size {
    return fmt.Errorf("directory size overflows int64 at %s", path)
}
size += info.Size()
Defensive patterns

Strategy: validation

Validate before calling

func saneFileSize(n int64) bool { return n >= 0 }

Type guard

func canAccumulate(total, next int64) bool {
    return next >= 0 && next <= math.MaxInt64-total
}

Try / catch

size, err := storage.MeasureDirectorySize(ctx, root)
var overflowErr = errors.New("directory size overflows")
if err != nil && strings.Contains(err.Error(), "overflows int64") {
    // fall back to a big.Int or per-subtree measurement
}

Prevention

When it happens

Trigger: filepath.Walk returns a FileInfo whose Size() is negative (sparse/odd files, corrupted metadata) or the accumulated size plus this file's size would exceed math.MaxInt64 during MeasureDirectorySize.

Common situations: Corrupted filesystem metadata or exotic virtual files reporting negative sizes; measuring an enormous tree (multi-exabyte aggregates, usually in tests with mocked FileInfo since real trees rarely reach MaxInt64).

Related errors


AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30). Data as JSON: /api/errors/62abcbe37b878579. Report an issue: GitHub.