# 无效的UTF-8符文串："\xff"

- **ID:** `go/invalid-utf-8-rune-string`
- **领域:** go
- **类别:** encoding_error
- **验证级别:** ai_generated
- **修复率:** 78%

## 根因

尝试解码非有效UTF-8的字节序列，通常来自未正确处理编码的外部数据源，如网络流或文件读取。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Go 1.21 | active | — | — |
| Go 1.22 | active | — | — |
| Go 1.23 | active | — | — |

## 解决方案

1. ```
   Use strings.ToValidUTF8() to replace invalid bytes with the Unicode replacement character U+FFFD
   ```
2. ```
   Read data as []byte and decode with utf8.Valid() validation before string conversion
   ```

## 无效尝试

- **** — Binary data cannot be safely represented as UTF-8 strings; this leads to data corruption and runtime panics. (95% 失败率)
- **** — These operations still expect valid UTF-8 and will produce the same error or silently corrupt data. (80% 失败率)
