python / python/cpython

zipapp creates executable files with wrong permissions bits

未关闭
#96,867 3 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

@pfmoore 已经在做这个了。

开始于 2026年7月30日。

stdlib type-bug
主要语言
Python
星标
77.2k
派生
36k
PR 合并指标
PR 指标待抓取

描述

Owing to the fact that open() has no flags field for marking a file as executable, and doing that after the fact is difficult (since it involves playing around with umask), the current implementation of zipapp uses the following code to attempt to set the file executable:

os.chmod(new_archive, os.stat(new_archive).st_mode | stat.S_IEXEC)

Which is incorrect: this sets only the execute bit for the user, and will never set it for the group or "other" categories, regardless of the umask.

This was discussed in a series of comments in #96772, starting around

https://github.com/python/cpython/issues/67679#issuecomment-1093675286

Create and open executable file respecting the Unix user's umask:

os.fdopen(os.open(filename, os.O_CREAT|os.O_RDWR), "rw")

and ending with

https://github.com/python/cpython/issues/67679#issuecomment-1093675294

OK, thanks. I don't propose to go there with the initial implementation. If it's a problem in practice, someone can raise a bug and we'll fix it then. (I've never seen actual Python code in the wild that does all of that...)

This is a problem in practice for us.

We're trying to replace the C version of Cockpit with a Python zipapp, and the file gets created with permissions that allow the current user to run it, but won't allow the file to be installed in /usr/bin so everyone can run it.

We can work around it easy enough — chmod +x in the Makefile after we call zipapp, but this is a bug in zipapp that really ought to be fixed.

For what it's worth, I think the os.fdopen() approach originally proposed by "dholth" is the best one.

Linked PRs
  • gh-151970

贡献指南

打开贡献指南

从这里开始

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

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

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