Skip to content
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

[SR-13276] Data.copyBytes(to:from:) crashes if data is sliced and range is nil #3975

Open
swift-ci opened this issue Jul 24, 2020 · 0 comments

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-13276
Radar None
Original Reporter jaspa (JIRA User)
Type Bug

Attachment: Download

Environment

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

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug, Crash, RunTimeCrash
Assignee None
Priority Medium

md5: d401b22b1fbde00b08152fd4d230599b

Issue 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.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant