Skip to content

Commit f27e65b

Browse files
authored
fix(hstr): Fix unsoundness of wtf8's transmutation (#11194)
**Description:** This PR fixed an unsoundness of `wtf8`'s transmutation by adding `#[repr(transparent)]` to `struct Wtf8`. The original forked code didn't add this requirement, making the using of `std::mem::transmute` unsound. Usage example: https://github.com/h-a-n-a/swc/blob/7142def3e26ea9607c0787714b414c31c2872117/crates/hstr/src/wtf8/mod.rs#L462-L464
1 parent 4d9633d commit f27e65b

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

.changeset/light-rats-peel.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
swc_core: patch
3+
hstr: patch
4+
---
5+
6+
fix(hstr): Fix unsoundness of `wtf8`'s transmutation

crates/hstr/src/wtf8/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,8 @@ impl Extend<CodePoint> for Wtf8Buf {
434434
/// A borrowed slice of well-formed WTF-8 data.
435435
///
436436
/// Similar to `&str`, but can additionally contain surrogate code points
437-
/// if they’re not in a surrogate pair.
437+
/// if they're not in a surrogate pair.
438+
#[repr(transparent)]
438439
pub struct Wtf8 {
439440
bytes: [u8],
440441
}

0 commit comments

Comments
 (0)