weaviate/weaviate · error

sanitize file path %q: %w

Error message

sanitize file path %q: %w

What it means

GetFileMetadata failed while validating the caller-supplied relative path before touching the filesystem. sanitizeFilePath rejects paths that are absolute, cannot have symlinks resolved (typically nonexistent file), or escape the shard root via symlink traversal. This wrapper only adds context; the real condition is the wrapped sanitizeFilePath error.

Source

Thrown at adapters/repos/db/shard_backup.go:593

		return fmt.Errorf("shard version path: %w", err)
	}
	return nil
}

func (s *Shard) GetFileMetadata(ctx context.Context, relativeFilePath string) (file.FileMetadata, error) {
	s.haltForTransferMux.Lock()
	defer s.haltForTransferMux.Unlock()

	if s.haltForTransferCount.Load() == 0 {
		return file.FileMetadata{}, fmt.Errorf("can not open file %q for reading: illegal state: shard %q is not paused for transfer",
			relativeFilePath, s.name)
	}

	s.mayResetInactivityDeadline()

	finalPath, err := s.sanitizeFilePath(relativeFilePath)
	if err != nil {
		return file.FileMetadata{}, fmt.Errorf("sanitize file path %q: %w", relativeFilePath, err)
	}
	return file.GetFileMetadata(finalPath)
}

func (s *Shard) GetFile(ctx context.Context, relativeFilePath string) (io.ReadCloser, error) {
	s.haltForTransferMux.Lock()
	defer s.haltForTransferMux.Unlock()

	if s.haltForTransferCount.Load() == 0 {
		return nil, fmt.Errorf("can not open file %q for reading: illegal state: shard %q is not paused for transfer",
			relativeFilePath, s.name)
	}

	s.mayResetInactivityDeadline()

	finalPath, err := s.sanitizeFilePath(relativeFilePath)
	if err != nil {
		return nil, fmt.Errorf("sanitize file path %q: %w", relativeFilePath, err)

View on GitHub (pinned to 75aa4b6d11)

Solutions

  1. Inspect the wrapped cause: an fs.ErrNotExist means the relative file does not exist in the shard directory; an 'outside shard root' or 'absolute path' cause means the caller passed an invalid/hostile path.
  2. Fix the caller (backup/replication file transfer) to pass only paths relative to the shard root that were obtained from shard directory listings.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at adapters/repos/db/shard_backup.go:593 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of weaviate/weaviate@75aa4b6d11 (2026-09-04). Data as JSON: /api/errors/20751df041dd698e. Report an issue: GitHub.