fix(ext/node): don't panic when main module path has invalid percent-encoding#35534
Merged
bartlomieju merged 3 commits intoJul 2, 2026
Merged
Conversation
…encoding
`process.argv[1]` is derived from `Deno.mainModule` during the node process
bootstrap by converting the `file:` URL to a path. That conversion calls
`decodeURIComponent`, which throws `URIError: URI malformed` when the path
contains invalid percent-encoding (e.g. a non-UTF-8 byte). Because this runs
in bootstrap, the uncaught throw aborts the runtime with a panic
("Bootstrap exception: URIError: URI malformed").
Guard the conversion and fall back to the raw specifier so a non-decodable
main module can't crash the process. The decode still matches Node, which
also throws from `fileURLToPath` for such paths; only the panic is fixed.
Closes denoland#34178
Keep the bootstrap panic guard (fall back to the raw specifier when the main module path can't be decoded), but stop exposing the helper on the internals bag purely for testing. The synthetic unit test drove the helper with a hand-made string and did not exercise the real bootstrap path, so remove it rather than leave a test-only entry on internals.
The mainModuleArgv refactor consolidated two Deno.mainModule reads into one, dropping the count from 32 to 31.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #34178.
When the node process polyfill bootstraps, it sets
process.argv[1]fromDeno.mainModuleby converting thefile:URL to a path. That conversion ends indecodeURIComponent, which throwsURIError: URI malformedif the path contains invalid percent-encoding (e.g. a non-UTF-8 byte). Since this happens during bootstrap, the uncaught throw aborts the runtime with a panic:This was hit in the wild via yt-dlp's
denoprovider (#34178).The decode itself is not wrong — Node throws the same
URIErrorfromfileURLToPathfor these paths — so this only fixes the crash: the conversion is guarded and falls back to the raw specifier when it can't be decoded, so a non-decodable main module no longer takes down the process.Reproducing the exact filesystem state is awkward on macOS (the path needs a non-UTF-8 byte), so the regression test exercises the extracted helper directly with a malformed URL.