8000 Wild pointer when using the Data.SubSequence · Issue #81833 · swiftlang/swift · GitHub
[go: up one dir, main page]

Skip to content
Wild pointer when using the Data.SubSequence #81833
@czf0613

Description

@czf0613

Description

This crash happens on macOS 15.5, I haven't tested it on other platforms.

I am writing a buffered reader like this.
When the buffer contains enough data, it returns it and cuts the first n bytes.

It will crash with an error called EXEC_ENDPOINT, which means Data could be a wild pointer.
Compiler has no warning when compiling this code.

Reproduction

import Foundation

final class Test {
    private var data = Data([1, 2, 3, 4, 5])

    func read(n: Int) async -> Data {
        while data.count < n {
            data.append(contentsOf: [6, 6, 6, 6])
        }

        let slice = data.prefix(n)
        data.removeFirst(n)

        return slice
    }
}

let obj = Test()

for i in 0..<10 {
    let data = await obj.read(n: 4)
    print("round: \(i + 1), value: \(data[0])")
}

Stack dump

Stack dump:
0.      Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -interpret Test.swift -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk -color-diagnostics -new-driver-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -empty-abi-descriptor -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -module-name Test -disable-clang-spi -target-sdk-version 15.5 -target-sdk-name macosx15.5 -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -in-process-plugin-server-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/libSwiftInProcPluginServer.dylib -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins
1.      Apple Swift version 6.1.2 (swiftlang-6.1.2.1.2 clang-1700.0.13.5)
2.      Compiling with effective version 5.10
3.      While running user code "Test.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             0x00000001085fae24 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend             0x00000001085f8c5c llvm::sys::RunSignalHandlers() + 112
2  swift-frontend             0x00000001085fb460 SignalHandler(int) + 360
3  libsystem_platform.dylib   0x0000000188d9c624 _sigtramp + 56
4  libsystem_platform.dylib   0x00000001112342c4 _sigtramp + 18446744071701101784
5  libsystem_platform.dylib   0x00000001112342c4 _sigtramp + 18446744071701101784
6  libswift_Concurrency.dylib 0x0000000271b4b454 swift::runJobInEstablishedExecutorContext(swift::Job*) + 248
7  libswift_Concurrency.dylib 0x0000000271b4c9b4 swift_job_runImpl(swift::Job*, swift::SerialExecutorRef) + 156
8  libdispatch.dylib          0x0000000188be1a7c _dispatch_main_queue_drain.cold.5 + 592
9  libdispatch.dylib          0x0000000188bb9db0 _dispatch_main_queue_drain + 180
10 libdispatch.dylib          0x0000000188bb9cec _dispatch_main_queue_callback_4CF + 44
11 CoreFoundation             0x0000000188e8bda4 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
12 CoreFoundation             0x0000000188e4ca9c __CFRunLoopRun + 1980
13 CoreFoundation             0x0000000188e4bc58 CFRunLoopRunSpecific + 572
14 CoreFoundation             0x0000000188ec5714 CFRunLoopRun + 64
15 libswift_Concurrency.dylib 0x0000000271b5cd04 swift_task_asyncMainDrainQueueImpl + 40
16 libswift_Concurrency.dylib 0x0000000271b53c68 swift_task_asyncMainDrainQueue + 92
17 libswift_Concurrency.dylib 0x0000000111234078 swift_task_asyncMainDrainQueue + 18446744067794404460
18 swift-frontend             0x00000001025a14c4 llvm::orc::runAsMain(int (*)(int, char**), llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>, std::__1::optional<llvm::StringRef>) + 908
19 swift-frontend             0x00000001024b7870 swift::SwiftJIT::runMain(llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>) + 628
20 swift-frontend             0x00000001024c4c5c 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>>&&) + 1052
21 swift-frontend             0x0000000102451840 processCommandLineAndRunImmediately(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>&&, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::FrontendObserver*, int&) + 504
22 swift-frontend             0x000000010244cffc 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*) + 1980
23 swift-frontend             0x000000010244c71c swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 2688
24 swift-frontend             0x000000010244fe44 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 3796
25 swift-frontend             0x000000010244dfd8 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3716
26 swift-frontend             0x00000001023d20bc swift::mainEntry(int, char const**) + 5428
27 dyld                       0x00000001889c2b98 start + 6076

Expected behavior

It should run without crashes. :)

Environment

swift-driver version: 1.120.5 Apple Swift version 6.1.2 (swiftlang-6.1.2.1.2 clang-1700.0.13.5)
Target: arm64-apple-macosx15.0

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.crashBug: A crash, i.e., an abnormal termination of softwaretriage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0