python / python/cpython

unexpected behavior of tempfile.TemporaryFile() for O_TMPFILE

Open
#96,531 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib type-bug
Dominant language
Python
Stars
77.2k
Forks
36k
PR merge metrics
PR metrics pending

Description

Bug report

When O_TMPFILE is available:

  1. tempfile.TemporaryFile(mode='wb') opens with O_RDWR instead of O_WRONLY, the opener callback ignores mode argument and always use _bin_openflags
  2. _bin_openflags has both O_CREAT and O_EXCL set, the opener callback removes O_CREAT from flags but leave O_EXCL, this is an undefined behavior according to Linux open(2) manpage

Your environment

  • CPython versions tested on: 3.10
  • Operating system and architecture: Linux x86_64
Linked PRs
  • gh-133235

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading tempfile.TemporaryFile and its opener callback, focusing on how the mode argument and _bin_openflags are used when O_TMPFILE is available. Check the Linux open(2) behavior for O_CREAT and O_EXCL, then verify that binary write mode uses the intended access flags without the undefined flag combination.

Written by the indexing model from the issue text.

Assessment

Tech stack
linux, python
Domain
operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.