`memmap` example in `README.md` contains undefined behavior
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 45/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- rust
调研方向
检查 README.md 中的 memmap 示例,尤其是 unsafe map.as_slice() 的使用和 UTF-8 检查。确认对映射文件的更改如何使结果失效,然后更新示例,使其不再允许报告的未定义行为。并验证文档中的示例仍与 API 匹配。
由索引模型根据 Issue 内容生成。
描述
I think that the example in the README.md of memmap contains a race condition which can lead to undefined behavior:
extern crate memmap;
use memmap::{Mmap, Protection};
use std::env;
use std::io;
use std::str;
fn run() -> Result<(), io::Error> {
let mut args = env::args().skip(1);
let input = args.next().expect("incorrect argument");
let map = Mmap::open_path(input, Protection::Read)?;
unsafe {
let all_bytes = map.as_slice();
if let Ok(file_str) = str::from_utf8(all_bytes) {
println!("{}", file_str);
} else {
println!("not utf8");
}
}
Ok(())
}
If the file changes after the UTF-8 check, the program prints a &str that contains non-UTF-8 bytes.
- 主要语言
- Rust
- 星标
- 2.1k
- 派生
- 48
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
brson/stdx 的其他 Issue
-
难度 5/5 一周以上 新手友好度 20/100
-
难度 5/5 一周以上 新手友好度 20/100
-
Include uuid未关闭
难度 2/5 1-3 小时 新手友好度 38/100
-
难度 2/5 1-3 小时 新手友好度 35/100
-
难度 5/5 一周以上 新手友好度 25/100
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 88/100
pop-os/cosmic-comp#2956 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
libp2p/rust-libp2p#6694 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
EmbarkStudios/cargo-deny#910 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
tursodatabase/turso#10054 ·
维护者通常 1 天内回复
-
build: Update rust version可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭dependencies
难度 2/5 1-3 小时 新手友好度 67/100
ibm-granite-community/granite-cli#229 ·
维护者通常 1 天内回复