Skip to content

fix: panic on multi-byte UTF-8 chars during hash placeholder scanning#8783

Closed
Copilot wants to merge 2 commits intomainfrom
copilot/fix-rolldown-panic-build
Closed

fix: panic on multi-byte UTF-8 chars during hash placeholder scanning#8783
Copilot wants to merge 2 commits intomainfrom
copilot/fix-rolldown-panic-build

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 19, 2026

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`...
Original prompt

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

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

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)


💬 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.

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 19, 2026

Deploy Preview for rolldown-rs ready!

Name Link
🔨 Latest commit 91322a5
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/69bbaa71e1d0df0008b9b35b
😎 Deploy Preview https://deploy-preview-8783--rolldown-rs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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
Copilot AI requested a review from shulaoda March 19, 2026 06:38
Copilot AI and others added 2 commits March 19, 2026 15:48
Co-authored-by: shulaoda <165626830+shulaoda@users.noreply.github.com>
@shulaoda shulaoda force-pushed the copilot/fix-rolldown-panic-build branch from 4993225 to 91322a5 Compare March 19, 2026 07:49
@shulaoda shulaoda marked this pull request as ready for review March 19, 2026 07:49
@shulaoda shulaoda closed this Mar 19, 2026
@shulaoda shulaoda deleted the copilot/fix-rolldown-panic-build branch March 19, 2026 07:56
@github-actions
Copy link
Copy Markdown
Contributor

Benchmarks Rust

group                                                        pr                                     target
-----                                                        --                                     ------
bundle/bundle@multi-duplicated-top-level-symbol              1.00     64.7±2.09ms        ? ?/sec    1.02     65.8±2.11ms        ? ?/sec
bundle/bundle@multi-duplicated-top-level-symbol-sourcemap    1.00     72.1±2.03ms        ? ?/sec    1.00     72.0±2.42ms        ? ?/sec
bundle/bundle@rome_ts                                        1.09    148.2±8.89ms        ? ?/sec    1.00    135.6±3.83ms        ? ?/sec
bundle/bundle@rome_ts-sourcemap                              1.00    157.2±3.82ms        ? ?/sec    1.00    157.0±3.01ms        ? ?/sec
bundle/bundle@threejs                                        1.00     58.8±1.67ms        ? ?/sec    1.02     59.7±2.61ms        ? ?/sec
bundle/bundle@threejs-sourcemap                              1.04     70.7±4.32ms        ? ?/sec    1.00     68.4±2.75ms        ? ?/sec
bundle/bundle@threejs10x                                     1.00    695.1±7.57ms        ? ?/sec    1.01    702.0±7.95ms        ? ?/sec
bundle/bundle@threejs10x-sourcemap                           1.00    790.8±8.33ms        ? ?/sec    1.01    796.9±5.57ms        ? ?/sec

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 19, 2026

Merging this PR will not alter performance

✅ 6 untouched benchmarks
⏩ 8 skipped benchmarks1


Comparing copilot/fix-rolldown-panic-build (91322a5) with main (bc4206d)

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Panic]: A panic occurred during the build process

2 participants