Commit 00bcbe0
Fix UB: replace unsafe String::from_utf8_unchecked (#7781)
with checked conversion
A panic in a CustomTransliterator can unwind through Insertable's Drop
impl without fully restoring UTF-8 validity, causing into_string() to
produce undefined behavior via from_utf8_unchecked. Use checked
from_utf8().expect() so this becomes a clean panic instead.
This one seemed correct to me (process: hammer on Claude until it gets a
good patch). Maybe there is a better way, but I think this one is ok.
## Changelog
- Fix UB in transliterator: use checked UTF-8 conversion instead of
`from_utf8_unchecked`
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent 9c0923d commit 00bcbe0
File tree
1 file changed
+26
-5
lines changed- components/experimental/src/transliterate/transliterator
1 file changed
+26
-5
lines changedLines changed: 26 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
32 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
| |||
50 | 52 | | |
51 | 53 | | |
52 | 54 | | |
| 55 | + | |
53 | 56 | | |
54 | | - | |
55 | | - | |
56 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
57 | 62 | | |
58 | 63 | | |
59 | 64 | | |
| |||
1055 | 1060 | | |
1056 | 1061 | | |
1057 | 1062 | | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
0 commit comments