uutils / uutils/coreutils

mktemp: incompatibilty with non UTF-8 file names and suffixes

Open
#9,718 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

U - mktemp
Dominant language
Rust
Stars
24.1k
Forks
2k
Avg merge
1d 5h
Merged PRs (30d)
365

Description

I'm working on coming up with some more "Good First Issue" breakdowns. Running uutils locally I've found some differences in the mktemp util

Description

The uutils implementation fails to create temporary files/directories when the template or --suffix contains invalid UTF-8 bytes, while GNU mktemp handles them correctly.

The high level cause is:

  1. The --suffix option is parsed as String instead of OsString, causing clap to reject non-UTF-8 arguments
  2. The template is converted with .to_str() which requires valid UTF-8, so it fails
  3. The Internal Params struct uses String for prefix and suffix fields instead of OsString

Reproduction

  # GNU mktemp works with non-UTF-8 in template
  /usr/bin/mktemp /tmp/test$'\x80'_XXXXXX
  # Output: /tmp/test�_aBcDeF (creates file successfully)
  # Exit: 0

  # uutils mktemp fails
  ./target/debug/mktemp /tmp/test$'\x80'_XXXXXX
  # Output: mktemp: invalid template, '/tmp/test�_XXXXXX'
  # Exit: 1

  # GNU mktemp works with non-UTF-8 in --suffix
  /usr/bin/mktemp --suffix=$'\x80\x81' /tmp/tmpXXXXXX
  # Output: /tmp/tmpaBcDeF�� (creates file successfully)
  # Exit: 0

  # uutils mktemp fails at argument parsing
  ./target/debug/mktemp --suffix=$'\x80\x81' /tmp/tmpXXXXXX
  # Output: error: invalid UTF-8 was detected in one or more arguments
  # Exit: 2

Impact

Not only does this have incompatibility with the GNU implementation, in general converting to string is slower than using the OsString directly so there could be some performance speedups by fixing this.

Guide to fixing:

Make sure to add integration tests for the suffix and file creation that validate that the file is created correctly and does not error out when using non-utf8 characters.

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 at the mktemp argument parsing, template conversion, and Internal Params handling described in the issue, focusing on the --suffix and template entry points. Add integration coverage for non-UTF-8 suffixes and templates, then run the mktemp tests to verify files and directories are created successfully without errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.