[Bug]: --publish rejects port 1 as out of range
- 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
Publish either side of a port mapping on port 1:
```
container run --rm --publish 1:80 nginx
container run --rm --publish 8080:1 nginx
```
Both fail:
```
invalid publish host port range: 1
invalid publish container port range: 1
```
### Problem description
`Parser.publishPort` validates the parsed range with a strict greater-than:
https://github.com/apple/container/blob/main/Sources/Services/ContainerAPIService/Client/Parser.swift#L704
```swift
guard hostPortRangeStart > 1,
hostPortRangeStart <= hostPortRangeEnd
else { ... }
guard containerPortRangeStart > 1,
containerPortRangeStart <= containerPortRangeEnd
else { ... }
```
TCP and UDP port numbers run from 1 to 65535, so the lower bound should be `>= 1`. The current comparison also rejects port 1 at the start of a range, so `--publish 1-100:1-100` fails as well.
Port 0 is correctly rejected either way, since it means "any port" rather than a specific one.
### 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
Research direction
Start in Sources/Services/ContainerAPIService/Client/Parser.swift at Parser.publishPort around line 704, then run the two --publish reproductions from the issue. Done means port 1 is accepted for host, container, and range endpoints while port 0 remains rejected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 86/100