Skip to content

test: cover over-long relative specifiers in compiled executables - #40918

Open
robobun wants to merge 1 commit into
mainfrom
robobun/d46d23ec/compile-long-specifier-tests
Open

robobun wants to merge 1 commit into
mainfrom
robobun/d46d23ec/compile-long-specifier-tests

Conversation

@robobun

@robobun robobun commented Aug 29, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Fix

Background

  • A compiled executable embeds its modules under a virtual root (/$bunfs/root/, B:/~BUN/root/ on Windows). A relative specifier is joined onto that root and looked up in the graph, as spelled and under its .js name.
  • PathBuffer is a fixed scratch buffer of MAX_PATH_BYTES (1024 on macOS, 4096 on Linux, 98302 on Windows). The old join wrote into it unchecked.
  • import() and require() specifiers longer than 1.5x MAX_PATH_BYTES are rejected before resolution. Worker specifiers have no cap. The test lengths sit between the two bounds on each platform.
Notes

Hand probes on main with a compiled two-file app from a cwd 71 bytes deep. ./ specifiers of 4081 to 4085 bytes (the .js append window on Linux), 5000, 6145, 98288 and 100000 bytes: the worker fires error, the preload constructor throws, require reports MODULE_NOT_FOUND, import reports ERR_MODULE_NOT_FOUND (or the ENAMETOOLONG cap past 6144 bytes). No abort.

One neighbouring abort remains and is out of scope here. From a short cwd (/tmp/probe), a ./ specifier of 4081 to 4085 bytes panics in Resolver::load_extension (src/resolver/resolver.rs:6012) with range end index 4097 out of range for slice of length 4096. That is the regular resolver's extension probe. It reproduces with plain bun main.js as well, before and after #40619. #39626 fixes it.

Test runs:

  • USE_SYSTEM_BUN=1 bun test test/bundler/bundler_compile.test.ts -t "LongerThanPathBuffer|LongerThanPathMax" on 1.4.1-canary d578a8c: 0 pass, 3 fail (SIGABRT).
  • bun bd test test/bundler/bundler_compile.test.ts -t "LongerThanPathBuffer|LongerThanPathMax" on main f189103: 3 pass.
  • bun bd test test/bundler/bundler_compile.test.ts: 85 pass, 1 fail (compile/HelloWorldWithProcessVersionsBun, which also fails on main without this change).

no test proof · iteration 0 · platform-specific test(s) that do not run on this machine, deferring to CI, which covers all platforms: test/bundler/bundler_compile.test.ts

Adds the tests from #38422 and #38428. In a `bun build --compile`
executable, a `./` specifier longer than the path buffer passed to
`new Worker`, a Worker `preload`, `import()` or `require()` aborted the
process with `panic: range end index 5012 out of range for slice of
length 4095`. #40619 moved the embedded-module lookup into
`StandaloneModuleGraph::resolve`, which joins with a checked join and
guards the `.js` append, so such a specifier now falls through to the
regular resolver. No test on main exercises that path: the 70000 byte
probe in `compile/EmbeddedResolveMisses` is rejected by the 1.5x
PATH_MAX cap before it reaches the resolver.
@coderabbitai

coderabbitai Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7300eb2b-f5fb-45ad-8b05-9ae33244a601

📥 Commits

Reviewing files that changed from the base of the PR and between f189103 and d19ce33.

📒 Files selected for processing (1)
  • test/bundler/bundler_compile.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.


Walkthrough

Changes

The pull request adds regression tests for oversized runtime specifiers in compiled executables. The tests cover module resolution, Worker error events, and oversized Worker preload paths.

Compiled runtime path handling

Layer / File(s) Summary
Oversized module specifier errors
test/bundler/bundler_compile.test.ts
Tests oversized relative require() and dynamic import() paths. They verify clean module-not-found errors and continued embedded sibling resolution.
Oversized Worker path errors
test/bundler/bundler_compile.test.ts
Tests oversized ./ and ../ Worker paths, boundary-length paths, and preload paths. They verify error events and constructor errors without process crashes.

Suggested reviewers: dylan-conway, jarred-sumner

Merge Risk: ⚪ Minimal · up to d19ce

This is a localized test-only change covering over-long relative specifiers in compiled executables; no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: tests for over-long relative specifiers in compiled executables.
Description check ✅ Passed The description is complete and relevant. It explains the problem, test-only scope, affected cases, expected behavior, platform-specific coverage, and verification results. It does not use the templat…
Full details: Description check

Explanation

The description is complete and relevant. It explains the problem, test-only scope, affected cases, expected behavior, platform-specific coverage, and verification results. It does not use the template headings exactly, but it provides the required information.


Comment @coderabbitai help to get the list of available commands.

@robobun

robobun commented Aug 29, 2026 •

Copy link
Copy Markdown
Collaborator Author

Status: #38422 and #38428 are closed as superseded by #40619. Their three tests are carried here unchanged apart from the comments. Verified: they abort on the pre-#40619 build (1.4.1-canary d578a8c) and pass on a debug build of main at f189103 with no change under src/.

CI (build 108367): 180 of 181 jobs pass. test/bundler/bundler_compile.test.ts passes on every lane. The one red job is darwin x64, on test/js/web/url/url.test.ts (TypeError: Invalid URL in the Unicode 16 IDNA test). That test fails on main as well and is unrelated to this change. Ready for review.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — test-only regression coverage for already-fixed panics, follows the file's itBundled conventions exactly.

What was reviewed:

  • All three tests await conditions (Promise.withResolvers wired to onerror, awaited import(), sync try/catch) — no sleeps or timeouts.
  • Magic lengths are justified in comments (PATH_MAX per platform, 1.5× cap, one-byte-short-then-.js-append boundary) and use Buffer.alloc(n, fill) per the debug-JSC guidance.
  • RelativeSpecifierLongerThanPathMax indirects require/import through locals so the bundler can't resolve them at build time, and re-resolves an embedded sibling afterward to prove the graph is still usable.
Extended reasoning...

Overview

This PR adds three itBundled compile-mode test cases to test/bundler/bundler_compile.test.ts, covering over-long relative specifiers in standalone (--compile) executables: runtime require()/import() past PATH_MAX, new Worker(spec) past the fixed path buffer (including the exact one-byte-short boundary where only the appended .js overflows), and an over-long Worker preload path. No source code is touched — the panics were already fixed by #40619; this backfills the missing coverage.

Security risks

None. Test-only additions with no runtime, build, or dependency changes. The fixtures run inside the bundler test harness's spawned subprocesses and touch no network or shared filesystem state.

Level of scrutiny

Low. The change is additive test coverage placed next to sibling tests (compile/EmbeddedResolveMisses, compile/WorkerRelativePathTSExtension) using the identical itBundled shape: compile: true, files, entryPointsRaw, run: { stdout, setCwd }. The PR description documents that all three fail with SIGABRT on the pre-fix canary and pass on bun bd test at main, satisfying the "test must fail with USE_SYSTEM_BUN=1" rule.

Other factors

The tests satisfy the REVIEW.md checklist for tests reviewers reject: Buffer.alloc over .repeat, no per-test timeouts, condition-awaited rather than time-awaited, specific error codes asserted (MODULE_NOT_FOUND / ERR_MODULE_NOT_FOUND) rather than bare "threw", comments cite the source constants behind every platform-branched length, and the Worker test enumerates the boundary matrix (./, ../, and each platform's buffer size). The req/imp indirection wrappers correctly defeat build-time resolution so the runtime path is exercised. No prior reviews or outstanding objections on the timeline.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant