swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.6k stars 10.37k forks source link

[SR-11666] URL.lastPathComponent.prefix(N) crashes if N is the exact length of the last path component string #54075

Open swift-ci opened 5 years ago

swift-ci commented 5 years ago
Previous ID SR-11666
Radar None
Original Reporter bryanpierce (JIRA User)
Type Bug
Environment macOS 10.14.6 Build tools from Xcode 11.1 uname -mprsv Darwin 18.7.0 Darwin Kernel Version 18.7.0: Tue Aug 20 16:57:14 PDT 2019; root:xnu-4903.271.2\~2/RELEASE_X86_64 x86_64 i386 swiftc --version Apple Swift version 5.1 (swiftlang-1100.0.270.13 clang-1100.0.33.7) Target: x86_64-apple-darwin18.7.0
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 113a2b8f1574fa9e503cde77f5f0d852

Issue Description:

When calling prefix(N) on the string returned from URL.lastPathComponent an NSRangeException is thrown if the string is of length N. This only occurs when built with the -O optimization flag.

Example program:

import Foundation

let url = URL(fileURLWithPath: "/System");
let prefix = url.lastPathComponent.prefix(6)

Stack trace:

theblixguy commented 5 years ago

Looks like SR-11605 which was recently fixed. cc @Catfish-Man

Catfish-Man commented 5 years ago

Sure does!