Skip to content

bug: FSCompressedFileSuffixes is a mutable exported map — data race risk #2223

Description

@pageton

Description

FSCompressedFileSuffixes (fs.go:456) is an exported mutable map[string]string. It is read during FSHandler initialization inside a sync.Once, but being exported, any caller can concurrently read/write this map while the Once executes.

var FSCompressedFileSuffixes = map[string]string{
    "br":   ".br",
    "gzip": ".gz",
}

If a user modifies this map concurrently with FS initialization, it's a data race on the map (concurrent map read/write causes a fatal panic in Go).

Impact

  • Fatal crash (concurrent map read and map write) if modified after import while FS is being initialized concurrently.
  • Low probability in typical usage but high severity when it occurs.

Suggested Fix

Either:

  1. Unexport the map and provide a SetCompressedFileSuffixes() function that copies.
  2. Copy the map once at init time in the sync.Once block, so the original can be freely modified.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions