From 254b7f0adf868561ca9a2b2ec5eee26cd5d71740 Mon Sep 17 00:00:00 2001 From: Thiago Gonzaga Date: Sat, 25 Jul 2026 16:19:21 -0300 Subject: [PATCH] Accept port 1 when validating published port ranges The lower bound for a published port range was checked with a strict greater-than, so port 1 was reported as an invalid range on both the host and container sides. TCP and UDP port numbers start at 1. Port 0 remains rejected, since it means "any port" rather than a specific one. Fixes #2014 --- Sources/Services/ContainerAPIService/Client/Parser.swift | 4 ++-- Tests/ContainerAPIClientTests/ParserTest.swift | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Sources/Services/ContainerAPIService/Client/Parser.swift b/Sources/Services/ContainerAPIService/Client/Parser.swift index 559796bca..56ab6b12d 100644 --- a/Sources/Services/ContainerAPIService/Client/Parser.swift +++ b/Sources/Services/ContainerAPIService/Client/Parser.swift @@ -703,13 +703,13 @@ public struct Parser { throw ContainerizationError(.invalidArgument, message: "invalid publish container port: \(containerPortText)") } - guard hostPortRangeStart > 1, + guard hostPortRangeStart >= 1, hostPortRangeStart <= hostPortRangeEnd else { throw ContainerizationError(.invalidArgument, message: "invalid publish host port range: \(hostPortText)") } - guard containerPortRangeStart > 1, + guard containerPortRangeStart >= 1, containerPortRangeStart <= containerPortRangeEnd else { throw ContainerizationError(.invalidArgument, message: "invalid publish container port range: \(containerPortText)") diff --git a/Tests/ContainerAPIClientTests/ParserTest.swift b/Tests/ContainerAPIClientTests/ParserTest.swift index 7684ff936..4b8b342b9 100644 --- a/Tests/ContainerAPIClientTests/ParserTest.swift +++ b/Tests/ContainerAPIClientTests/ParserTest.swift @@ -109,6 +109,15 @@ struct ParserTest { #expect(result[0].count == 1) } + @Test + func testPublishPortOne() throws { + let result = try Parser.publishPorts(["127.0.0.1:1:1/tcp"]) + #expect(result.count == 1) + #expect(result[0].hostPort == UInt16(1)) + #expect(result[0].containerPort == UInt16(1)) + #expect(result[0].count == 1) + } + @Test func testPublishPortInvalidProtocol() throws { #expect {