Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit
Swift apple-silicond3dmetaldxmtdxvkgame-porting-toolkitgptkmac-gamingmacosmetalfxrosetta-2steamsteam-playwinewinecx
Safely reject incomplete ntdll section headers
NotProtonNot48d7ce03110d
diff --git a/app/Sources/NotProtonApp/Model/NtdllPatcher.swift b/app/Sources/NotProtonApp/Model/NtdllPatcher.swiftindex 867bfef..dc260dd 100644--- a/app/Sources/NotProtonApp/Model/NtdllPatcher.swift+++ b/app/Sources/NotProtonApp/Model/NtdllPatcher.swift@@ -468,6 +468,7 @@ enum NtdllPatcher {detail: String(localized: "The \(patch.arch.rawValue) ntdll image ends at \(hex(imageSize)), and the detour section was pinned at \(hex(patch.caveRVA))."))}+ try requireRange(header, 40, in: bytes, describing: String(localized: "A header field"))guard header + 40 <= headersSize, bytes[header ..< header + 40].allSatisfy({ $0 == 0 }) else {throw StepFailure(step: step,diff --git a/app/Tests/NotProtonAppTests/NtdllPatcherTests.swift b/app/Tests/NotProtonAppTests/NtdllPatcherTests.swiftindex 2d826c2..2c9366a 100644--- a/app/Tests/NotProtonAppTests/NtdllPatcherTests.swift+++ b/app/Tests/NotProtonAppTests/NtdllPatcherTests.swift@@ -191,6 +191,14 @@ struct NtdllPatcherTests {}}+ @Test("A section header slot truncated despite SizeOfHeaders is refused", arguments: [0, 1, 39])+ func sectionPlacementNeedsCompleteHeader(bytesPresent: Int) throws {+ let image = Data(stubImage().prefix(StubPE.tableEnd + bytesPresent))+ #expect(throws: StepFailure.self) {+ try NtdllPatcher.apply(sectionPatch(), to: image, payload: Data([0x90]))+ }+ }+// MARK: - Refusals@Test("A hook site holding something else is refused")