Unknown `encoding` segfaults R (unchecked Riconv_open result)

未关闭 适合新手
#425 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
r
领域
backend

调研方向

从 src/processx-connection.c 入手,重点查看 processx__connection_to_utf8(),并追踪 Riconv_open() 的结果如何传递给 Riconv()。使用 issue 中的示例 processx::run("echo", "hi", encoding = "bytes") 重现问题,然后检查不受支持的编码是否会引发 R 错误,同时有效编码是否仍能正常工作。issue 没有指定测试文件;请添加或查找覆盖这两种情况的测试。

由索引模型根据 Issue 内容生成。

描述

bug

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,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

相似的 Issue

更多 R Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。