apple / apple/container

[Bug]: --mount rejects a directive whose value contains "="

Open Beginner friendly
#2,012 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
49.9k
Forks
1.8k
Avg merge
1d 20h
Merged PRs (30d)
22

Description

### I have done the following

- [x] I have searched the existing issues
- [x] If possible, I've reproduced the issue using the 'main' branch of this project

### Steps to reproduce

Run a container with a mount whose source path contains an equals sign:

```
container run --rm --mount type=virtiofs,source=/tmp/a=b,destination=/mnt alpine true
```

The command fails with:

```
invalid directive format missing value source=/tmp/a=b in type=virtiofs,source=/tmp/a=b,destination=/mnt
```

Creating the directory first makes no difference, because the failure happens while parsing the flag.

### Problem description

`Parser.mount` splits each comma-separated directive on `=` with `maxSplits: 2`:

https://github.com/apple/container/blob/main/Sources/Services/ContainerAPIService/Client/Parser.swift#L371

In Swift, `maxSplits` counts splits rather than resulting elements, so a value that itself contains `=` produces three components:

```swift
"source=/tmp/a=b".split(separator: "=", maxSplits: 2)
// ["source", "/tmp/a", "b"]
```

The code then requires exactly two components and throws otherwise:

```swift
if keyVal.count != 2 {
throw ContainerizationError(.invalidArgument, message: "invalid directive format missing value \(part) in \(mount)")
}
```

A directive should split on the first `=` only, so that everything after it is the value. `maxSplits: 1` produces `["source", "/tmp/a=b"]`.

Equals signs are legal in POSIX path names, so any bind mount whose source or destination contains one is currently unusable.

This is the same defect that #1978 and #1999 fix for `Parser.labels`. Neither touches `Parser.mount`, so mounts remain affected.

### Environment

- OS: macOS 26.5.2 (25F84)
- Xcode: 26.6 (17F113)
- Container: main at 07ff3c0 (also present in 1.1.0)

### Code of Conduct

- [x] I agree to follow this project's Code of Conduct

Contributor guide

Open the contributing guide

Research direction

Start at Parser.mount in Sources/Services/ContainerAPIService/Client/Parser.swift around line 371, then reproduce the issue with the provided container run command. Verify that a mount source or destination containing an equals sign is accepted as one value and that the existing invalid-directive behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
cli
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
85/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.