Skip to content

fix JSON output panicking on infinite and NaN floats - #7725

Merged
philrz merged 1 commit into
mainfrom
json-nonfinite-floats
Nov 25, 2026
Merged

philrz merged 1 commit into
mainfrom
json-nonfinite-floats

Conversation

@philrz

@philrz philrz commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

JSON numbers can't represent infinity or NaN, so the JSON writer panicked on any such value. That's easy to hit, because a float division by zero gives +Inf, -Inf, or NaN (integer division by zero gives an error value instead). It affected -f json, -j, -J, and json_stringify(). Through super db serve, the server caught the panic but returned a 200 OK cut off at the first such value, e.g., [1] for values 1, 1.0/0, 3.

On current tip of main, commit f7e3eb6:

$ super -version && super -j -c "values 1, 1.0/0, 3"
Version: v0.4.0-122-gf7e3eb63d
panic: json: unsupported value: +Inf

goroutine 1 [running]:
...

On this branch:

$ super -version && super -j -c "values 1, 1.0/0, 3"
Version: v0.4.0-123-ga5cd231a5
1
"+Inf"
3

These values are now written as the strings "+Inf", "-Inf", and "NaN", as they appear in SUP. That follows how the writer already handles durations, timestamps, IP addresses, and other values JSON can't represent, and float map keys were already written this way (map{+Inf:1} gives {"+Inf":1}). The strings cast back to floats with '+Inf'::float64. This Gist compares other choices, such as null, the Postgres spelling "Infinity", and what DuckDB, jq, Python, and JavaScript do.

The new ztest fails on main. Timing of JSON output for 10 million floats is unchanged.

JSON numbers can't represent infinity or NaN, so the JSON writer
panicked with "json: unsupported value: +Inf" on any such value, e.g.,
the result of a float division by zero like 1.0/0. That broke -f json,
-j, -J, and json_stringify(), and super db serve returned a 200
response cut off at the first such value.

These values are now written as the strings "+Inf", "-Inf", and "NaN",
as they appear in SUP. The writer already turns other values JSON can't
represent, such as durations, timestamps, and IP addresses, into
strings.
@philrz philrz self-assigned this Nov 25, 2026
@philrz
philrz requested a review from a team November 25, 2026 06:00
@philrz
philrz merged commit 74a41eb into main Nov 25, 2026
2 checks passed
@philrz
philrz deleted the json-nonfinite-floats branch November 25, 2026 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants