fix: panic on multi-byte UTF-8 chars during hash placeholder scanning#8783
Closed
fix: panic on multi-byte UTF-8 chars during hash placeholder scanning#8783
Conversation
✅ Deploy Preview for rolldown-rs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Copilot
AI
changed the title
[WIP] [Panic] Fix panic during build process in Rolldown
fix: panic on multi-byte UTF-8 chars during hash placeholder scanning
Mar 19, 2026
Co-authored-by: shulaoda <165626830+shulaoda@users.noreply.github.com>
4993225 to
91322a5
Compare
Contributor
Benchmarks Rust |
Merging this PR will not alter performance
Comparing Footnotes
|
graphite-app bot
pushed a commit
that referenced
this pull request
Mar 21, 2026
…or (#8790) From #8783 to trigger preview When source files contain multi-byte UTF-8 characters (e.g. Chinese filenames in SVG imports), the hash placeholder iterator could panic because the computed `search_end` byte offset landed in the middle of a multi-byte character, making `&str[left_pos..search_end]` an invalid slice. ## Changes - **`crates/rolldown_utils/src/hash_placeholder.rs`** — Replace `str::find` over `self.s[left_pos..search_end]` with `memchr::memmem::find` over `self.s.as_bytes()[left_pos..search_end]`. Since all placeholder delimiters (`!~{`, `}~`) are ASCII, byte-level search is correct and the resulting `right_pos` is always a valid char boundary. - Add regression tests covering placeholders adjacent to Chinese characters and cases where the 3-byte boundary of a CJK character straddles `search_end`. ``` thread panicked at crates/rolldown_utils/src/hash_placeholder.rs:56:38: byte index 1045 is not a char boundary; it is inside '级' (bytes 1044..1047) of `...vue.runtime.esm-bundler-!~{001}~.js`... ``` <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>[Panic]: A panic occurred during the build process</issue_title> > <issue_description>### Panic message > > ```Shell > rendering chunks (411)...Rolldown panicked. This is a bug in Rolldown, not your code. > > thread '<unnamed>' (39028) panicked at crates\rolldown_utils\src\hash_placeholder.rs:56:38: > byte index 1045 is not a char boundary; it is inside '级' (bytes 1044..1047) of `import{C as e,D as t,Dt as n,E as r,J as i,K as a,O as o,S as s,Ut as ee,X as c,Z as l,b as u,ct as d,m as f,st as p,vt as m,x as h}from"./vue.runtime.esm-bundler-!~{001}~.js";import{t as g}from"./objectSpread2-!~{003}~.js";import{s as _}from"./router-!~{0`[...] > Rolldown panicked. This is a bug in Rolldown, not your code. > Rolldown panicked. This is a bug in Rolldown, not your code. > note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace > Rolldown panicked. This is a bug in Rolldown, not your code. > Rolldown panicked. This is a bug in Rolldown, not your code. > > thread '<unnamed>' (45852) panicked at crates\rolldown_utils\src\hash_placeholder.rs:56:38: > byte index 582 is not a char boundary; it is inside '级' (bytes 581..584) of `import{C as e,D as t,Dt as n,J as r,K as i,O as a,Q as o,S as s,T as c,U as l,Ut as u,W as d,b as f,ct as p,m,n as h,st as g,u as _,vt as v,x as y}from"./vue.runtime.esm-bundler-!~{001}~.js";import{a as b}from"./dist-!~{005}~.js";import"./router-!~{00d}~.j`[...] > Rolldown panicked. This is a bug in Rolldown, not your code. > ``` > > ### Reproduction > > It seems the issue was related to Chinese characters in my SVG file name. After I renamed the Chinese names to English, the problem was fixed. > > ### System Info > > ```Shell > System: > OS: Windows 11 10.0.26200 > CPU: (22) x64 Intel(R) Core(TM) Ultra 9 185H > Memory: 6.36 GB / 31.43 GB > Binaries: > Node: 22.14.0 - C:\Program Files\nodejs\node.EXE > Yarn: 1.22.22 - C:\Users\jay\AppData\Roaming\npm\yarn.CMD > npm: 10.9.2 - C:\Program Files\nodejs\npm.CMD > pnpm: 10.30.2 - C:\Users\jay\AppData\Roaming\npm\pnpm.CMD > Browsers: > Chrome: 146.0.7680.154 > Edge: Chromium (140.0.3485.54) > Firefox: 141.0.3 - C:\Program Files\Mozilla Firefox\firefox.exe > Internet Explorer: 11.0.26100.7309 > ``` > > ### Additional context > > _No response_</issue_description> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes #8782 - Fixes #8795 - Fixes #8806 - Fixes #8808 <!-- START COPILOT CODING AGENT TIPS --> --- 💬 Send tasks to Copilot coding agent from [Slack](https://gh.io/cca-slack-docs) and [Teams](https://gh.io/cca-teams-docs) to turn conversations into code. Copilot posts an update in your thread when it's finished.
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.
When source files contain multi-byte UTF-8 characters (e.g. Chinese filenames in SVG imports), the hash placeholder iterator could panic because the computed
search_endbyte offset landed in the middle of a multi-byte character, making&str[left_pos..search_end]an invalid slice.Changes
crates/rolldown_utils/src/hash_placeholder.rs— Replacestr::findoverself.s[left_pos..search_end]withmemchr::memmem::findoverself.s.as_bytes()[left_pos..search_end]. Since all placeholder delimiters (!~{,}~) are ASCII, byte-level search is correct and the resultingright_posis always a valid char boundary.search_end.Original prompt
💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.