Unknown `encoding` segfaults R (unchecked Riconv_open result)
还没有人认领这个 Issue。
评估
调研方向
从 src/processx-connection.c 入手,重点查看 processx__connection_to_utf8(),并追踪 Riconv_open() 的结果如何传递给 Riconv()。使用 issue 中的示例 processx::run("echo", "hi", encoding = "bytes") 重现问题,然后检查不受支持的编码是否会引发 R 错误,同时有效编码是否仍能正常工作。issue 没有指定测试文件;请添加或查找覆盖这两种情况的测试。
由索引模型根据 Issue 内容生成。
描述
An encoding that iconv does not recognise crashes R as soon as the process produces output:
processx::run("echo", "hi", encoding = "bytes")
#> *** caught segfault ***
#> address 0x2f, cause 'invalid permissions'
"nonsense-encoding" crashes the same way. Valid names ("", "UTF-8", "latin1") work. A command that prints nothing does not crash, because processx__connection_to_utf8() returns before it calls Riconv().
Cause
src/processx-connection.c, in processx__connection_to_utf8() (unchanged on main at 7adf8aa):
if (! ccon->iconv_ctx) ccon->iconv_ctx = Riconv_open("UTF-8", encoding);
The return value is never checked. For an unknown encoding, Riconv_open() returns (void *) -1, and that value is then passed to Riconv(). The lldb backtrace shows EXC_BAD_ACCESS in Riconv(cd=0xffffffffffffffff, ...), called from processx__connection_to_utf8.
Possible fix
Patching only this line makes "bytes" and "nonsense-encoding" raise an R error instead of crashing, and "UTF-8" still works:
if (! ccon->iconv_ctx) {
void *ctx = Riconv_open("UTF-8", encoding);
if (ctx == (void *) -1) {
R_THROW_ERROR("Unsupported encoding: '%s'", encoding);
}
ccon->iconv_ctx = ctx;
}
Checking encoding in process$new() / run() before the process starts would give the error earlier and with a clearer message.
Environment
processx 3.9.0, R 4.6.1, macOS 27.0.1 (arm64).
- 主要语言
- R
- 星标
- 247
- 派生
- 44
- 平均合并
- 1 小时 10 分钟
- 30 天内合并 PR
- 2
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
hubverse-org/hubDevs#83 ·
-
data_bio2rarify - doc - dimensions wrong可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 1/5 1 小时以内 新手友好度 88/100
leppott/BioMonTools#162 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
bug
难度 1/5 1 小时以内 新手友好度 78/100
-
publications
难度 1/5 1 小时以内 新手友好度 85/100
epiforecasts/epiforecasts.github.io#161 ·
维护者通常 1 天内回复