Skip to content

Parse the passwd and group files as UTF-8 instead of ASCII - #962

Open
i098 wants to merge 1 commit into
apple:mainfrom
i098:fix/containerization-user-2376
Open

i098 wants to merge 1 commit into
apple:mainfrom
i098:fix/containerization-user-2376

Conversation

@i098

@i098 i098 commented Oct 11, 2026

Copy link
Copy Markdown

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Motivation and Context

Closes apple/container#2376.

User.parse reads /etc/passwd and /etc/group with String(contentsOf:encoding: .ascii). One non-ASCII byte in either file, for example an accented GECOS name from useradd -c 'José Müller', makes the read fail. Every later container exec then fails with NSCocoaErrorDomain Code=259, for every user.

This change decodes the files with String(decoding:as: UTF8.self). That fixes UTF-8 names. It also keeps a legacy non-UTF-8 byte (for example Latin-1) from failing the whole file. The parser only splits on : and newlines, so a replacement character in a GECOS field has no effect.

Repro, from the issue:

container run --detach --name passwdtest registry.fedoraproject.org/fedora:43 sleep infinity
container exec passwdtest useradd -c 'José Müller' passwdtest
container exec passwdtest true

Before: container exec fails with NSCocoaErrorDomain Code=259 "The file isn’t in the correct format.".
After: User.parse reads the file, so the exec no longer fails at this step.

Testing

  • Tested locally
  • Added/updated tests
  • Added/updated docs

I ran the unit tests on macOS 26.2 with Swift 6.3.3. I did not run container exec end to end.

swift test --filter ContainerizationOSTests.UsersTests with the old User.swift:

✘ Test testExecUserNonASCIIPasswdGroup() recorded an issue at UserTests.swift:154:6: Caught error: Error Domain=NSCocoaErrorDomain Code=259 "The file couldn’t be opened because it isn’t in the correct format."
✘ Test testExecUserInvalidUTF8Passwd() recorded an issue at UserTests.swift:183:6: Caught error: Error Domain=NSCocoaErrorDomain Code=259 "The file couldn’t be opened because it isn’t in the correct format."
✘ Test run with 5 tests in 1 suite failed after 0.005 seconds with 2 issues.

swift test --filter ContainerizationOSTests with this change:

✔ Test run with 70 tests in 7 suites passed after 1.065 seconds.

swift format leaves both changed files unchanged.

I am new to open source, and this pull request was made with AI assistance.

User.parse read both files with String(contentsOf:encoding: .ascii), so a single non-ASCII byte (for example an accented GECOS name) made every exec fail with NSCocoaErrorDomain Code=259. Decode leniently instead, so legacy non-UTF-8 bytes are not fatal either. Add regression tests for both cases.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: container exec fails when /etc/passwd or /etc/group contains non-ASCII characters

1 participant