Skip to content

AttributedSubstring.== crashes on empty strings #4634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cobbal opened this issue Sep 21, 2022 · 1 comment · Fixed by #4635
Closed

AttributedSubstring.== crashes on empty strings #4634

cobbal opened this issue Sep 21, 2022 · 1 comment · Fixed by #4635
Assignees

Comments

@cobbal
Copy link

cobbal commented Sep 21, 2022

When comparing 2 empty AttributedSubstrings from different base AttributedStrings, something crashes. Tested on mac, untested on other platforms.

SubstrCrash.swift:

import Foundation

func sub(_ s: AttributedString) -> AttributedSubstring { s[s.startIndex..<s.endIndex] }
print(sub("") == sub(""))

Result:

 $ swift --version
swift-driver version: 1.45.2 Apple Swift version 5.6 (swiftlang-5.6.0.323.62 clang-1316.0.20.8)
Target: x86_64-apple-macosx12.0

$ swift SubstrCrash.swift
Stack dump:
0.	Program arguments: /Applications/Xcode-13.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -interpret SubstrCrash.swift -enable-objc-interop -stack-check -sdk /Applications/Xcode-13.3.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk -color-diagnostics -new-driver-path /Applications/Xcode-13.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -resource-dir /Applications/Xcode-13.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -module-name SubstrCrash -target-sdk-version 12.3
1.	Apple Swift version 5.6 (swiftlang-5.6.0.323.62 clang-1316.0.20.8)
2.	Compiling with the current language version
3.	While running user code "SubstrCrash.swift"
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x0000000110b14de7 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
1  swift-frontend           0x0000000110b13e38 llvm::sys::RunSignalHandlers() + 248
2  swift-frontend           0x0000000110b15440 SignalHandler(int) + 288
3  libsystem_platform.dylib 0x00007ff8021b7dfd _sigtramp + 29
4  libsystem_platform.dylib 0x0000000000000001 _sigtramp + 18446603370545578529
5  libswiftFoundation.dylib 0x00007ff813bf2716 function signature specialization <Arg[2] = Dead> of static Foundation.AttributedSubstring.== infix(Foundation.AttributedSubstring, Foundation.AttributedSubstring) -> Swift.Bool + 2982
6  libswiftFoundation.dylib 0x0000000113b9d0ff function signature specialization <Arg[2] = Dead> of static Foundation.AttributedSubstring.== infix(Foundation.AttributedSubstring, Foundation.AttributedSubstring) -> Swift.Bool + 18446603374875555215
7  swift-frontend           0x000000010b927560 llvm::orc::runAsMain(int (*)(int, char**), llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, llvm::Optional<llvm::StringRef>) + 1792
8  swift-frontend           0x000000010b883dcd swift::RunImmediately(swift::CompilerInstance&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, swift::IRGenOptions const&, swift::SILOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >&&) + 13613
9  swift-frontend           0x000000010b84b2c3 performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 2259
10 swift-frontend           0x000000010b83e953 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 21107
11 swift-frontend           0x000000010b7fc5d4 swift::mainEntry(int, char const**) + 1108
12 dyld                     0x0000000113ba652e start + 462
[1]    87164 illegal hardware instruction  swift SubstrCrash.swift
@jmschonfeld
Copy link
Contributor

Thanks for finding this! You're right, it looks a bug in AttributedString.Runs.== surfaced through AttributedSubstring.== - I'll post a fix for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants