Uploaded image for project: 'Swift'
  1. Swift
  2. SR-13276

Data.copyBytes(to:from:) crashes if data is sliced and range is nil

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Foundation
    • Environment:

      Apple Swift version 5.2.4 (swiftlang-1103.0.32.9 clang-1103.0.32.53)
      Target: x86_64-apple-darwin19.5.0

      Description

      The expected output of the attached crasher.swift is (by running swift crasher.swift)

      x = 10
      x = 20
      x = 30
      

      but instead crashes with

      x = 10
      x = 20
      Stack dump:
      0.	Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret crasher.swift -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -module-name crasher
      1.	Apple Swift version 5.2.4 (swiftlang-1103.0.32.9 clang-1103.0.32.53)
      2.	While running user code "crasher.swift"
      0  swift                    0x000000011395a4ea PrintStackTraceSignalHandler(void*) + 42
      1  swift                    0x0000000113959cc0 SignalHandler(int) + 352
      2  libsystem_platform.dylib 0x00007fff6f7a95fd _sigtramp + 29
      3  libswiftCore.dylib       0x00007fff6ef4bc08 $ss5UInt8Vs23CustomStringConvertiblesMc + 0
      4  libswiftFoundation.dylib 0x00007fff6f069f71 $s10Foundation4DataV9copyBytes2to4fromSiSryxG_SnySiGSgtlF + 209
      5  libswiftFoundation.dylib 0x000000011806dbb5 $s10Foundation4DataV9copyBytes2to4fromSiSryxG_SnySiGSgtlF + 2835365141
      6  libswiftFoundation.dylib 0x000000011806d87c $s10Foundation4DataV9copyBytes2to4fromSiSryxG_SnySiGSgtlF + 2835364316
      7  libswiftFoundation.dylib 0x000000011806dbf8 $s10Foundation4DataV9copyBytes2to4fromSiSryxG_SnySiGSgtlF + 2835365208
      8  libswiftCore.dylib       0x00007fff6ecca5ac $ss17withUnsafePointer2to_q_xz_q_SPyxGKXEtKr0_lF + 12
      9  libswiftCore.dylib       0x00007fff6eeb7899 $ss24withUnsafeMutablePointer2to_q_xz_q_SpyxGKXEtKr0_lF + 9
      10 libswiftCore.dylib       0x000000011806d534 $ss24withUnsafeMutablePointer2to_q_xz_q_SpyxGKXEtKr0_lF + 2837142692
      11 swift                    0x000000010f6dd0aa llvm::MCJIT::runFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>) + 458
      12 swift                    0x000000010f6e411b llvm::ExecutionEngine::runFunctionAsMain(llvm::Function*, 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&, char const* const*) + 2011
      13 swift                    0x000000010f6b91da performCompileStepsPostSILGen(swift::CompilerInstance&, swift::CompilerInvocation&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, bool, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, bool, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 14362
      14 swift                    0x000000010f6adb95 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 55813
      15 swift                    0x000000010f623b73 main + 1283
      16 libdyld.dylib            0x00007fff6f5b0cc9 start + 1
      

      The error most likely occurs because https://github.com/apple/swift/blob/d543069/stdlib/public/Darwin/Foundation/Data.swift#L2254 doesn't use Data.startIndex but assumes 0 as the start index.

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            jaspa Janek Spaderna
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: