Skip to content

fix(incremental): reject a tsbuildinfo tuple of the wrong length - #1050

Merged
camc314 merged 2 commits into
oxc-project:mainfrom
magurotuna:fix/buildinfo-tuple-length
Nov 20, 2026
Merged

camc314 merged 2 commits into
oxc-project:mainfrom
magurotuna:fix/buildinfo-tuple-length

Conversation

@magurotuna

Copy link
Copy Markdown
Member

A .tsbuildinfo with "referencedMap":[[5]] made tsrs panic (attempt to subtract with overflow). With "root":[[1,2,3]] or "root":[[]], tsrs used the file and did not write it again. tsgo cannot read these files, so it builds without an old state and writes the file again.

Go reads these entries into a [2]int (BuildInfoRoot, BuildInfoReferenceMapEntry), and encoding/json/v2 returns an error for an array of another length. as_uint_tuple padded or truncated the array. It now rejects it, as Go does.

Tests: buildinfo_tuple_array_length (one and three elements in referencedMap, three and zero in root). All four fail without the fix.

AI assistance: written with Claude Code.

A `.tsbuildinfo` entry in `root`, `referencedMap`, or `resolvedRoot` that is
an array with a length other than 2 made tsgo treat the file as unreadable
and build without an old state. tsrs padded or truncated the array:
`"referencedMap":[[5]]` gave a list ID of 0 and panicked in
`to_file_path_set` (subtract with overflow), and `"root":[[1,2,3]]` was read
as the range 1 to 2, so the file was not written again.

Go reads these entries with `json.Unmarshal` into a `[2]int`
(`buildInfo.go`, the `UnmarshalJSON` methods of `BuildInfoRoot`,
`BuildInfoReferenceMapEntry`, and `BuildInfoResolvedRoot`). The `json`
package of tsgo is `encoding/json/v2`, which returns an error when the
JSON array length differs from the Go array length. `as_uint_tuple` now
requires exactly N elements, and its comment states that rule.

Tests: `buildinfo_tuple_array_length` in the `tsrs_cli` integration tests
(a one-element and a three-element `referencedMap` entry, and a
three-element and an empty `root` entry). Expected results are from tsgo
at the pinned commit. All four fail without the fix.

AI assistance: written with Claude Code.
@camc314
camc314 added this pull request to the merge queue Nov 20, 2026
@codspeed

codspeed Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 4 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

βœ… 8 untouched benchmarks
⏩ 8 skipped benchmarks1


Comparing magurotuna:fix/buildinfo-tuple-length (8801ae3) with main (9f74013)

Open in CodSpeed

Footnotes

  1. 8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

Merged via the queue into oxc-project:main with commit 8e025ef Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants