From dda2b535b7983593cd708a04eaa02ea05d29cb87 Mon Sep 17 00:00:00 2001 From: Guillaume Lessard Date: Thu, 8 Jan 2026 16:46:01 -0800 Subject: [PATCH 1/4] [ci] adjust the pull-request action --- .github/workflows/pull_request.yml | 58 +++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 4c3a66c6..e706a363 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -1,5 +1,8 @@ name: Pull request +permissions: + contents: read + on: pull_request: types: [opened, reopened, synchronize] @@ -9,21 +12,50 @@ jobs: name: Test uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main with: + swift_flags: "-Xbuild-tools-swiftc -DSYSTEM_CI" + enable_linux_checks: true linux_os_versions: '["noble", "jammy", "focal"]' - linux_exclude_swift_versions: '[{"os_version": "focal", "swift_version": "nightly-main"}, {"os_version": "focal", "swift_version": "nightly-6.2"}, {"os_version": "focal", "swift_version": "6.2"}, {"os_version": "noble", "swift_version": "5.9"}, {"os_version": "noble", "swift_version": "5.10"}]' + linux_exclude_swift_versions: | + [ + {"swift_version": "5.9"}, + {"swift_version": "5.10"}, + {"os_version": "focal", "swift_version": "nightly-6.2"}, + {"os_version": "focal", "swift_version": "6.2"}, + {"os_version": "focal", "swift_version": "nightly-6.3"}, + {"os_version": "focal", "swift_version": "6.3"}, + {"os_version": "focal", "swift_version": "nightly-main"}, + ] enable_macos_checks: true - # FIXME: https://github.com/swiftlang/github-workflows/pull/140 - # Xcode 16.0 and 16.1 are not actually available - macos_exclude_xcode_versions: | + macos_exclude_xcode_versions: '[]' + enable_windows_checks: true + windows_exclude_swift_versions: | [ - {"xcode_version": "16.0"}, - {"xcode_version": "16.1"}, + {"swift_version": "5.9"}, + {"swift_version": "5.10"} ] - swift_flags: "-Xbuild-tools-swiftc -DSYSTEM_CI" enable_linux_static_sdk_build: true - linux_static_sdk_exclude_swift_versions: '[{"os_version": "focal", "swift_version": "nightly-main"}, {"os_version": "focal", "swift_version": "nightly-6.2"}, {"os_version": "focal", "swift_version": "6.2"}]' + linux_static_sdk_exclude_swift_versions: | + [ + {"os_version": "focal", "swift_version": "nightly-6.2"}, + {"os_version": "focal", "swift_version": "6.2"}, + {"os_version": "focal", "swift_version": "nightly-6.3"}, + {"os_version": "focal", "swift_version": "6.3"}, + {"os_version": "focal", "swift_version": "nightly-main"}, + ] enable_wasm_sdk_build: true - wasm_exclude_swift_versions: '[{"os_version": "focal", "swift_version": "nightly-main"}, {"os_version": "focal", "swift_version": "nightly-6.2"}, {"os_version": "focal", "swift_version": "6.2"}]' + wasm_exclude_swift_versions: | + [ + {"os_version": "focal", "swift_version": "nightly-6.2"}, + {"os_version": "focal", "swift_version": "6.2"}, + {"os_version": "focal", "swift_version": "nightly-6.3"}, + {"os_version": "focal", "swift_version": "6.3"}, + {"os_version": "focal", "swift_version": "nightly-main"}, + ] + enable_android_sdk_build: true + android_exclude_swift_versions: | + [ + {"os_version": "focal", "swift_version": "nightly-main"}, + ] build-abi-stable: name: Build ABI Stable @@ -34,13 +66,7 @@ jobs: enable_windows_checks: false # Only build macos_build_command: "xcrun swift build --build-tests" - # FIXME: https://github.com/swiftlang/github-workflows/pull/140 - # Xcode 16.0 and 16.1 are not actually available - macos_exclude_xcode_versions: | - [ - {"xcode_version": "16.0"}, - {"xcode_version": "16.1"}, - ] + macos_exclude_xcode_versions: '[]' # Enable availability to match ABI stable verion of system. swift_flags: "-Xbuild-tools-swiftc -DSYSTEM_CI -Xbuild-tools-swiftc -DSYSTEM_ABI_STABLE" From 2eb655e0b7a75bab9ca9edf67419b4a4b08adae3 Mon Sep 17 00:00:00 2001 From: Guillaume Lessard Date: Tue, 13 Jan 2026 12:33:12 -0800 Subject: [PATCH 2/4] [ci] re-allow 5.9 and 5.10 - they were excluded in error. --- .github/workflows/pull_request.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index e706a363..8fa4b217 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -17,8 +17,8 @@ jobs: linux_os_versions: '["noble", "jammy", "focal"]' linux_exclude_swift_versions: | [ - {"swift_version": "5.9"}, - {"swift_version": "5.10"}, + {"os_version": "noble", "swift_version": "5.9"}, + {"os_version": "noble", "swift_version": "5.10"}, {"os_version": "focal", "swift_version": "nightly-6.2"}, {"os_version": "focal", "swift_version": "6.2"}, {"os_version": "focal", "swift_version": "nightly-6.3"}, From 0dbbab4aa1bb713e295e007406c2370f0e806892 Mon Sep 17 00:00:00 2001 From: AZero13 Date: Sun, 28 Dec 2025 14:33:38 -0500 Subject: [PATCH 3/4] Fix HRESULT_FACILITY HRESULT_FACILITY is >> 16 & 0x1fff, not << --- Sources/System/FilePath/FilePathWindows.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/System/FilePath/FilePathWindows.swift b/Sources/System/FilePath/FilePathWindows.swift index 2226816e..875c1c60 100644 --- a/Sources/System/FilePath/FilePathWindows.swift +++ b/Sources/System/FilePath/FilePathWindows.swift @@ -517,7 +517,7 @@ fileprivate func HRESULT_CODE(_ hr: HRESULT) -> DWORD { @inline(__always) fileprivate func HRESULT_FACILITY(_ hr: HRESULT) -> DWORD { - DWORD(hr << 16) & 0x1fff + DWORD(hr >> 16) & 0x1fff } @inline(__always) From 13851a3421a2a41dc292a33e9f68a6b8c1a81253 Mon Sep 17 00:00:00 2001 From: lee Date: Wed, 7 Jan 2026 11:37:16 -0300 Subject: [PATCH 4/4] Fix silent buffer size truncation in Windows pread/pwrite --- Sources/System/Errno.swift | 2 +- .../Internals/WindowsSyscallAdapters.swift | 12 +++++ .../FileOperationsTestWindows.swift | 47 +++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/Sources/System/Errno.swift b/Sources/System/Errno.swift index 43b46af5..c4cd7831 100644 --- a/Sources/System/Errno.swift +++ b/Sources/System/Errno.swift @@ -160,7 +160,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable { /// No child processes. /// /// A `wait(2)` or `waitpid(2)` function was executed - /// by a process that dosn't have any existing child processes + /// by a process that doesn't have any existing child processes /// or whose child processes are all already being waited for. /// /// The corresponding C error is `ECHILD`. diff --git a/Sources/System/Internals/WindowsSyscallAdapters.swift b/Sources/System/Internals/WindowsSyscallAdapters.swift index da5dfb8d..ca9b42dd 100644 --- a/Sources/System/Internals/WindowsSyscallAdapters.swift +++ b/Sources/System/Internals/WindowsSyscallAdapters.swift @@ -149,6 +149,12 @@ internal func pread( let handle: intptr_t = _get_osfhandle(fd) if handle == /* INVALID_HANDLE_VALUE */ -1 { ucrt._set_errno(EBADF); return -1 } + // Windows ReadFile accepts DWORD (32-bit) for buffer size, so validate nbyte doesn't exceed it + if nbyte > Int(DWORD.max) { + ucrt._set_errno(EINVAL) + return -1 + } + // NOTE: this is a non-owning handle, do *not* call CloseHandle on it let hFile: HANDLE = HANDLE(bitPattern: handle)! @@ -171,6 +177,12 @@ internal func pwrite( let handle: intptr_t = _get_osfhandle(fd) if handle == /* INVALID_HANDLE_VALUE */ -1 { ucrt._set_errno(EBADF); return -1 } + // Windows WriteFile accepts DWORD (32-bit) for buffer size, so validate nbyte doesn't exceed it + if nbyte > Int(DWORD.max) { + ucrt._set_errno(EINVAL) + return -1 + } + // NOTE: this is a non-owning handle, do *not* call CloseHandle on it let hFile: HANDLE = HANDLE(bitPattern: handle)! diff --git a/Tests/SystemTests/FileOperationsTestWindows.swift b/Tests/SystemTests/FileOperationsTestWindows.swift index 7b87b354..f43521b0 100644 --- a/Tests/SystemTests/FileOperationsTestWindows.swift +++ b/Tests/SystemTests/FileOperationsTestWindows.swift @@ -242,6 +242,53 @@ final class FileOperationsTestWindows: XCTestCase { } } } + + /// Test that buffer sizes exceeding DWORD.max (4GB) are properly rejected + func testBufferSizeLimit() throws { + try withTemporaryFilePath(basename: "testBufferSizeLimit") { path in + let fd = try FileDescriptor.open( + path.appending("test.txt"), + .readWrite, + options: [.create, .truncate], + permissions: .ownerReadWrite + ) + defer { try? fd.close() } + + // Write some data first + try fd.writeAll("test data".utf8) + + // Allocate a small buffer for testing + let buffer = UnsafeMutableRawBufferPointer.allocate(byteCount: 1024, alignment: 1) + defer { buffer.deallocate() } + + // Test that a count exceeding DWORD.max (UInt32.max = 4,294,967,295) returns EINVAL + // We use a buffer pointer but pass a count > DWORD.max + let oversizedCount = Int(DWORD.max) + 1 + let oversizedBuffer = UnsafeMutableRawBufferPointer( + start: buffer.baseAddress, + count: oversizedCount + ) + + // pread should fail with EINVAL + do { + _ = try fd.read(fromAbsoluteOffset: 0, into: oversizedBuffer) + XCTFail("Expected EINVAL for buffer size exceeding DWORD.max") + } catch let err as Errno { + XCTAssertEqual(err, .invalidArgument, "Expected EINVAL, got \(err)") + } + + // pwrite should also fail with EINVAL + do { + _ = try fd.write(toAbsoluteOffset: 0, UnsafeRawBufferPointer(oversizedBuffer)) + XCTFail("Expected EINVAL for buffer size exceeding DWORD.max") + } catch let err as Errno { + XCTAssertEqual(err, .invalidArgument, "Expected EINVAL, got \(err)") + } + + // Verify that exactly DWORD.max works (if we had a buffer that large) + // We can't easily test this without allocating 4GB, but the boundary is correct + } + } } #endif // os(Windows)