swift-system icon indicating copy to clipboard operation
swift-system copied to clipboard

Assertion failure in FilePathParsing.swift

Open compnerd opened this issue 11 months ago • 3 comments

Assertion Failure: https://github.com/apple/swift-system/blob/main/Sources/System/FilePath/FilePathParsing.swift#L226 Test case: https://github.com/apple/swift-system/blob/main/Tests/SystemTests/FilePathTests/FilePathComponentsTest.swift#L247

> [IO.Path]::GetFullPath("//foo///bar/baz/")
\\foo\bar\baz\
> [IO.Path]::GetPathRoot("//foo///bar/baz/")
\\foo\bar
> [IO.Path]::GetPathRoot([IO.Path]::GetFullPath("//foo///bar/baz/"))
\\foo\bar

This also matches the Microsoft documentation on path normalization:

Normally, any path passed to a Windows API is (effectively) passed to the GetFullPathName function and normalized. There is one important exception: a device path that begins with a question mark instead of a period. Unless the path starts exactly with \?\ (note the use of the canonical backslash), it is normalized.

Originally posted by @compnerd in https://github.com/apple/swift-system/pull/101#discussion_r1262802765

compnerd avatar Jul 25 '23 19:07 compnerd

I believe that this is related to the assertion failure that I see on Windows:

SystemPackage/FilePathParsing.swift:226: Assertion failed

  * frame #0: 0x00007ffd10c9c3d3 swiftCore.dll`Swift._assertionFailure(_: Swift.StaticString, _: Swift.String, file: Swift.StaticString, line: Swift.UInt, flags: Swift.UInt32) -> Swift.Never + 755
    frame #1: 0x00007ff7ec75b67e swift-systemPackageTests.xctest`FilePath._parseComponent(i=7, self=SystemPackage.FilePath @ 0x000000490cdfd4e0) at FilePathParsing.swift:226:5
    frame #2: 0x00007ff7ec74d17a swift-systemPackageTests.xctest`FilePath.ComponentView.subscript.getter(position=(_storage = 7), self=SystemPackage.FilePath.ComponentView @ 0x000000490cdfd5b0) at FilePathComponentView.swift:120:21
    frame #3: 0x00007ff7ec74fe05 swift-systemPackageTests.xctest`FilePath.ComponentView.subscript.read(position=(_storage = 7), self=SystemPackage.FilePath.ComponentView @ 0x000000490cdfd620) at FilePathComponentView.swift:0
    frame #4: 0x00007ff7ec74fd3d swift-systemPackageTests.xctest`protocol witness for Collection.subscript.read in conformance FilePath.ComponentView at <compiler-generated>:0
    frame #5: 0x00007ffd10c9a849 swiftCore.dll`Swift.Collection.first.getter : Swift.Optional<I,_0_0.Element> + 537
    frame #6: 0x00007ff7ec74b292 swift-systemPackageTests.xctest`FilePath.ComponentView._invariantCheck(self=SystemPackage.FilePath.ComponentView @ 0x000000490cdfdd50) at FilePathComponentView.swift:228:7
    frame #7: 0x00007ff7ec74ae2f swift-systemPackageTests.xctest`FilePath.ComponentView.init(path=SystemPackage.FilePath @ 0x000000490cdfddc8) at FilePathComponentView.swift:38:7
    frame #8: 0x00007ff7ec74c68a swift-systemPackageTests.xctest`FilePath.components.getter(self=SystemPackage.FilePath @ 0x000000490cdfde20) at FilePathComponentView.swift:45:11
    frame #9: 0x00007ff7ec793dce swift-systemPackageTests.xctest`TestPathComponents.pathComponents.getter(self=SystemTests.TestPathComponents @ 0x000000490cdfe030) at FilePathComponentsTest.swift:24:62
    frame #10: 0x00007ff7ec794138 swift-systemPackageTests.xctest`TestPathComponents.failureMessage(reason=nil, self=SystemTests.TestPathComponents @ 0x000000490cdfe030) at FilePathComponentsTest.swift:34:21
    frame #11: 0x00007ff7ec79e408 swift-systemPackageTests.xctest`protocol witness for TestCase.failureMessage(_:) in conformance TestPathComponents at <compiler-generated>:0
    frame #12: 0x00007ff7ec7df788 swift-systemPackageTests.xctest`implicit closure #2 in TestCase.fail(_:) at <compiler-generated>:0
    frame #13: 0x00007ff7ec7df7b9 swift-systemPackageTests.xctest`partial apply for implicit closure #2 in TestCase.fail(_:) at <compiler-generated>:0
    frame #14: 0x00007ffd5608da30 XCTest.dll`partial apply for implicit closure #1 in XCTAssertNil(_:_:file:line:) [inlined] implicit closure #1 () -> Swift.String in XCTest.XCTAssertNil(_: @autoclosure () throws -> Swift.Optional<Any>, _: @autoclosure () -> Swift.String, file: Swift.StaticString, line: Swift.UInt) -> () at <compiler-generated>:0 [opt]
    frame #15: 0x00007ffd5608da2d XCTest.dll`partial apply for implicit closure #1 in XCTAssertNil(_:_:file:line:) at <compiler-generated>:0 [opt]
    frame #16: 0x00007ffd5608da30 XCTest.dll`partial apply for implicit closure #1 in XCTAssertNil(_:_:file:line:) [inlined] implicit closure #1 () -> Swift.String in XCTest.XCTAssertNil(_: @autoclosure () throws -> Swift.Optional<Any>, _: @autoclosure () -> Swift.String, file: Swift.StaticString, line: Swift.UInt) -> () at <compiler-generated>:0 [opt]
    frame #17: 0x00007ffd5608da2d XCTest.dll`partial apply for implicit closure #1 in XCTAssertNil(_:_:file:line:) at <compiler-generated>:0 [opt]
    frame #18: 0x00007ffd5608a00c XCTest.dll`_XCTEvaluateAssertion(assertion=<unavailable>, message=0x00007ffd5608dc70 XCTest.dll`partial apply forwarder for implicit closure #1 () -> Swift.String in XCTest.XCTAssertTrue(_: @autoclosure () throws -> Swift.Bool, _: @autoclosure () -> Swift.String, file: Swift.StaticString, line: Swift.UInt) -> (), file="S:\\SourceCache\\swift-project\\swift-system\\Tests\\SystemTests\\FilePathTests\\FilePathComponentsTest.swift", line=247, expression=0x00007ffd5608ccd0 XCTest.dll`partial apply forwarder for closure #1 () throws -> XCTest._XCTAssertionResult in XCTest.XCTAssertTrue(_: @autoclosure () throws -> Swift.Bool, _: @autoclosure () -> Swift.String, file: Swift.StaticString, line: Swift.UInt) -> ()) at XCTAssert.swift:100:79 [opt]
    frame #19: 0x00007ffd5608a18c XCTest.dll`XCTAssert(_:_:file:line:) [inlined] XCTest.XCTAssertTrue(expression=0x0000000000000000, message=0x0000000000000000, file=<unavailable>, line=247) throws -> Swift.Bool, _: @autoclosure () -> Swift.String, file: Swift.StaticString, line: Swift.UInt) -> () at XCTAssert.swift:395:5 [opt]
    frame #20: 0x00007ffd5608a11c XCTest.dll`XCTAssert(expression=<unavailable>, message=<unavailable>, file="S:\\SourceCache\\swift-project\\swift-system\\Tests\\SystemTests\\FilePathTests\\FilePathComponentsTest.swift", line=247) at XCTAssert.swift:164:5 [opt]
    frame #21: 0x00007ff7ec7dd609 swift-systemPackageTests.xctest`TestCase.fail(reason=nil, self=SystemTests.TestPathComponents @ 0x000000490cdfe7c0) at TestingInfrastructure.swift:137:5
    frame #22: 0x00007ff7ec7dd899 swift-systemPackageTests.xctest`TestCase.expectEqual<Self>(expected=some, actual=some, message=nil, self=SystemTests.TestPathComponents @ 0x000000490cdfe7c0) at TestingInfrastructure.swift:72:7
    frame #23: 0x00007ff7ec794721 swift-systemPackageTests.xctest`TestPathComponents.testComponents(self=SystemTests.TestPathComponents @ 0x000000490cdfe8b0) at FilePathComponentsTest.swift:53:5
    frame #24: 0x00007ff7ec795f2e swift-systemPackageTests.xctest`TestPathComponents.runAllTests(self=SystemTests.TestPathComponents @ 0x000000490cdfe8b0) at FilePathComponentsTest.swift:96:5
    frame #25: 0x00007ff7ec79d218 swift-systemPackageTests.xctest`closure #1 in FilePathComponentsTest.testCases($0=SystemTests.TestPathComponents @ 0x000000490cdfe8b0) at FilePathComponentsTest.swift:252:28
   frame #26: 0x00007ff7ec79cf4b swift-systemPackageTests.xctest`FilePathComponentsTest.testCases(self=0x0000014c4e944650) at FilePathComponentsTest.swift:252:15
    frame #27: 0x00007ff7ec7e6570 swift-systemPackageTests.xctest`implicit closure #4 in implicit closure #3 in variable initialization expression of static FilePathComponentsTest.__allTests__FilePathComponentsTest(self=0x0000014c4e944650) at SystemTests.swift:34:23
    frame #28: 0x00007ff7ec7ea1ab swift-systemPackageTests.xctest`thunk for @escaping @callee_guaranteed () -> () at <compiler-generated>:0
    frame #29: 0x00007ffd560837e0 XCTest.dll`partial apply for thunk for @escaping @callee_guaranteed () -> (@out ()) [inlined] reabstraction thunk helper from @escaping @callee_guaranteed () -> (@out ()) to @escaping @callee_guaranteed () -> () at <compiler-generated>:0 [opt]
    frame #30: 0x00007ffd560837dd XCTest.dll`partial apply for thunk for @escaping @callee_guaranteed () -> (@out ()) at <compiler-generated>:0 [opt]
    frame #31: 0x00007ffd5608367c XCTest.dll`partial apply for closure #1 in test<T>(_:) at XCTestCase.swift:320:13 [opt]
    frame #32: 0x00007ffd5608366d XCTest.dll`partial apply for closure #1 in test<T>(_:) at <compiler-generated>:0 [opt]
    frame #33: 0x00007ffd56083633 XCTest.dll`partial apply for thunk for @escaping @callee_guaranteed (@guaranteed XCTestCase) -> (@error @owned Error) [inlined] reabstraction thunk helper from @escaping @callee_guaranteed (@guaranteed XCTest.XCTestCase) -> (@error @owned Swift.Error) to @escaping @callee_guaranteed (@in_guaranteed XCTest.XCTestCase) -> (@out (), @error @owned Swift.Error) at <compiler-generated>:0 [opt]
    frame #34: 0x00007ffd5608362d XCTest.dll`partial apply for thunk for @escaping @callee_guaranteed (@guaranteed XCTestCase) -> (@error @owned Error) at <compiler-generated>:0 [opt]
    frame #35: 0x00007ffd56074e88 XCTest.dll`partial apply for thunk for @escaping @callee_guaranteed (@in_guaranteed XCTestCase) -> (@out (), @error @owned Error) [inlined] reabstraction thunk helper from @escaping @callee_guaranteed (@in_guaranteed XCTest.XCTestCase) -> (@out (), @error @owned Swift.Error) to @escaping @callee_guaranteed (@guaranteed XCTest.XCTestCase) -> (@error @owned Swift.Error) at <compiler-generated>:0 [opt]
    frame #36: 0x00007ffd56074e73 XCTest.dll`partial apply for thunk for @escaping @callee_guaranteed (@in_guaranteed XCTestCase) -> (@out (), @error @owned Error) at <compiler-generated>:0 [opt]
    frame #37: 0x00007ffd5608190a XCTest.dll`XCTestCase.invokeTest(self=0x0000014c4e944650) at XCTestCase.swift:124:21 [opt]
    frame #38: 0x00007ffd56081526 XCTest.dll`XCTestCase.perform(run=<unavailable>, self=0x0000014c4e944650) at XCTestCase.swift:99:9 [opt]
    frame #39: 0x00007ffd56086364 XCTest.dll`XCTest.run(self=0x0000014c4e944650) at XCAbstractTest.swift:52:9 [opt]
    frame #40: 0x00007ffd560844db XCTest.dll`XCTestSuite.perform(run=0x0000014c4e9a9f00, self=0x0000014c4e942e30) at XCTestSuite.swift:49:18 [opt]
    frame #41: 0x00007ffd56086364 XCTest.dll`XCTest.run(self=0x0000014c4e942e30) at XCAbstractTest.swift:52:9 [opt]
    frame #42: 0x00007ffd560844db XCTest.dll`XCTestSuite.perform(run=0x0000014c4e9a1e50, self=0x0000014c4e93f770) at XCTestSuite.swift:49:18 [opt]
    frame #43: 0x00007ffd56086364 XCTest.dll`XCTest.run(self=0x0000014c4e93f770) at XCAbstractTest.swift:52:9 [opt]
    frame #44: 0x00007ffd560844db XCTest.dll`XCTestSuite.perform(run=0x0000014c4e93f460, self=0x0000014c4e93d690) at XCTestSuite.swift:49:18 [opt]
    frame #45: 0x00007ffd56086364 XCTest.dll`XCTest.run(self=0x0000014c4e93d690) at XCAbstractTest.swift:52:9 [opt]
    frame #46: 0x00007ffd5608075c XCTest.dll`XCTMain(testCases=<unavailable>, arguments=1 value, observers=1 value) at XCTestMain.swift:145:23 [opt]
    frame #47: 0x00007ffd56080254 XCTest.dll`XCTMain(_:) [inlined] XCTest.XCTMain(testCases=12 values, arguments=1 value) throws -> ())>)>, arguments: Swift.Array<Swift.String>) -> Swift.Never at XCTestMain.swift:67:5 [opt]
    frame #48: 0x00007ffd560801f5 XCTest.dll`XCTMain(testCases=12 values) at XCTestMain.swift:63:5 [opt]
    frame #49: 0x00007ff7ec7ea752 swift-systemPackageTests.xctest`static Runner.main(self=swift_systemPackageTests.Runner) at runner.swift:8:9
    frame #50: 0x00007ff7ec7ea769 swift-systemPackageTests.xctest`static Runner.$main(self=swift_systemPackageTests.Runner) at <compiler-generated>:0
    frame #51: 0x00007ff7ec7ea789 swift-systemPackageTests.xctest`main at runner.swift:6:8
    frame #52: 0x00007ff7ec7eacf0 swift-systemPackageTests.xctest`int __scrt_common_main_seh(void) + 268
(l frame #53: 0x00007ffd7d7a26ad kernel32.dll`BaseThreadInitThunk + 29
    frame #54: 0x00007ffd7ea2aa68 ntdll.dll`RtlUserThreadStart + 40

compnerd avatar Jul 25 '23 19:07 compnerd

CC: @milseman @lorentey

compnerd avatar Jul 25 '23 19:07 compnerd

Linked to rdar://113002701

glessard avatar Jul 27 '23 23:07 glessard