Concurrent assignment of DisableModifiers or DisableEscapeHTML is a data race
Summary
DisableModifiers and DisableEscapeHTML are exported package-level bool variables. Parsers and AppendJSONString read them while application code may assign them. Under the Go memory model that is a data race. The race detector reports it.
Unlike a concurrent map write, a bool race does not raise fatal error: concurrent map read and map write and does not by itself abort the process. It can leave a goroutine observing a flag value that another goroutine has already replaced.
Both variables are documented as process-global flags that should be set once, before any other gjson call. The storage cannot express that contract. A racy read of DisableEscapeHTML changes whether <, >, and & are escaped.
This is not reachable by JSON alone. It does not corrupt memory. Severity is medium: a detector warning and a stale flag, not an unrecoverable runtime abort.
- Package:
github.com/tidwall/gjson - Confirmed revision:
8d89927eff414537088a6092d53fecf6711c1e75 - CWE-362 (Concurrent Execution Using Shared Resource with Improper Synchronization)
- File:
gjson.go
| Symbol | Exported write | Reads |
|---|---|---|
DisableEscapeHTML |
line 2066 | AppendJSONString, line 2091 |
DisableModifiers |
line 2961 | isDotPiperChar, line 988; Get, lines 2165 & 2170; Result.Path, line 3567 |
A tested Pull Request addressing this issue with atomic storage and accessors is submitted concurrently.
Source: tidwall/gjson