Repository navigation
Avoid slicing truncated source map charset values - #65465
Merged
Jake Bailey (jakebailey) merged 2 commits intoNov 14, 2026
Merged
Jake Bailey (jakebailey) merged 2 commits into
Jake Bailey (jakebailey) merged 2 commits into
Conversation
A data URL can end before the UTF-8 charset prefix is complete. Check its length before comparing that prefix so malformed metadata follows the existing skip and external-map fallback paths instead of panicking. Keep charset matching case-insensitive.
Keep the charset comparison and both length checks tied to a single local constant so the accepted prefix cannot drift between them.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the change guarding source-map charset parsing against truncated input.
No open issues 🎉
What changed in this PR
This PR prevents source-map parsing from panicking on truncated UTF-8 charset metadata in data URLs, preserving case-insensitive matching and existing external-map fallback behavior.
Changes:
- Check the charset length before slicing and comparing its prefix.
- Add parser tests for malformed and valid data URLs.
- Verify malformed data URLs are skipped and external maps remain usable.
| File | Description |
|---|---|
tsc/internal/sourcemap/source_mapper.go |
Guards charset parsing against truncated input. |
tsc/internal/sourcemap/source_mapper_test.go |
Adds parser and external-map fallback regression tests. |
Review effort: Balanced
Jake Bailey (jakebailey)
requested a review
from Andrew Branch (andrewbranch)
November 13, 2026 18:06
Andrew Branch (andrewbranch)
approved these changes
Nov 13, 2026
Jake Bailey (jakebailey)
deleted the
compiler-fixes/sourcemap-data-url
branch
November 14, 2026 00:03
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.
A data URL can end before the UTF-8 charset prefix is complete. Check its length before comparing that prefix so malformed metadata follows the existing skip and external-map fallback paths instead of panicking. Keep charset matching case-insensitive.