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-14789] Linux - Getting value from property InputStream.streamError traps. #3956

Open
swift-ci opened this issue Jun 17, 2021 · 3 comments

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-14789
Radar rdar://problem/79456450
Original Reporter GalenRhodes1967 (JIRA User)
Type Bug
Environment
  • Ubuntu 20.04.2 LTS (GNU/Linux 5.4.0-74-generic x86_64)
    • Swift version 5.4 (swift-5.4-RELEASE) Target: x86_64-unknown-linux-gnu
  • Ubuntu 20.04.2 LTS (GNU/Linux 5.8.0-55-generic x86_64)
    • Swift version 5.4 (swift-5.4-RELEASE) Target: x86_64-unknown-linux-gnu
  • Ubuntu 20.04.2 LTS (GNU/Linux 5.4.0-1036-raspi aarch64) - Raspberry PI 4 (4GB)
    • Swift version 5.5-dev (LLVM c64e53b8742ea89, Swift 3f6eb2f8a0a1287) Target: aarch64-unknown-linux-gnu
  • Ubuntu 20.04.2 LTS (GNU/Linux 4.9.241-70 aarch64) - ODROID C4
    • Swift version 5.5-dev (LLVM c64e53b8742ea89, Swift 3f6eb2f8a0a1287) Target: aarch64-unknown-linux-gnu
Additional Detail from JIRA
Votes 0
Component/s Foundation, Standard Library
Labels Bug
Assignee None
Priority Medium

md5: 8041e548b25e485dcc7fa65e64e981dc

Issue Description:

Attempting to read the value of property streamError in InputStream class causes a trap with the error message "Illegal Instruction" on Linux. I've tried this on 4 different Linux machines. Works fine in macOS.

import Foundation
import CoreFoundation

let testDataDir: String = "Tests/RubiconTests/Files"

guard let inputStream = InputStream(fileAtPath: "\(testDataDir)/Test_UTF-8.xml") else {
    print("Unable to create input stream!")
    exit(1)
}
inputStream.open()
if let e = inputStream.streamError { // <----- Crashes here.
    print("File not opened: \(e.localizedDescription)")
    exit(1)
}
var array  = [ UInt8 ](repeating: 0, count: 100)
let result = inputStream.read(&array, maxLength: 100)
guard result >= 0 else {
    let e   = inputStream.streamError // <----- Crashes here.
    let msg = (e?.localizedDescription ?? "Unknown Error")
    print("Error reading file: \(msg)")
    exit(1)
}
let str = String(bytes: array, encoding: .utf8)
print(str ?? "???")
inputStream.close()
exit(0)
@typesanitizer
Copy link

@swift-ci create

@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
@alanfalloon
Copy link

This is still present in 5.9. Using the following example script:

import Foundation

let inputStream = InputStream(data: Data())
print("streamError = \(String(describing: inputStream.streamError))")

I reproduced it in the Swift 5.9 nightly docker image

$ docker run --init --tty --interactive --volume=$PWD:/src --workdir=/src swiftlang/swift:nightly-5.9-jammy /bin/bash --login
 ################################################################
 #								#
 # Swift Nightly Docker Image					#
 # Tag: swift-5.9-DEVELOPMENT-SNAPSHOT-2023-09-01-a			#
 #								#
 ################################################################

root@840db0f726f3:/src# swift main.swift
Stack dump:
0.	Program arguments: /usr/bin/swift-frontend -frontend -interpret main.swift -disable-objc-interop -color-diagnostics -new-driver-path /usr/bin/swift-driver -empty-abi-descriptor -resource-dir /usr/lib/swift -module-name main -plugin-path /usr/lib/swift/host/plugins -plugin-path /usr/local/lib/swift/host/plugins
1.	Swift version 5.9-dev (LLVM 26bcbd4dcaa236c, Swift 46a3b414a3fe592)
2.	Compiling with the current language version
3.	While running user code "main.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):
/usr/bin/swift-frontend(+0x70a59e3)[0x56094fbfa9e3]
/usr/bin/swift-frontend(+0x70a372e)[0x56094fbf872e]
/usr/bin/swift-frontend(+0x70a5d5a)[0x56094fbfad5a]
/lib/x86_64-linux-gnu/libc.so.6(+0x42520)[0x7f51df1bc520]
/usr/lib/swift/linux/libFoundation.so(+0x53f2ad)[0x7f51d7ca72ad]
[0x7f51df730115]
/usr/bin/swift-frontend(+0xfb171c)[0x560949b0671c]
/usr/bin/swift-frontend(+0xe3633d)[0x56094998b33d]
/usr/bin/swift-frontend(+0xde24b0)[0x5609499374b0]
/usr/bin/swift-frontend(+0xdddb42)[0x560949932b42]
/usr/bin/swift-frontend(+0xddcb6a)[0x560949931b6a]
/usr/bin/swift-frontend(+0xdf26f5)[0x5609499476f5]
/usr/bin/swift-frontend(+0xddfc29)[0x560949934c29]
/usr/bin/swift-frontend(+0xdde955)[0x560949933955]
/usr/bin/swift-frontend(+0xc27e73)[0x56094977ce73]
/lib/x86_64-linux-gnu/libc.so.6(+0x29d90)[0x7f51df1a3d90]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80)[0x7f51df1a3e40]
/usr/bin/swift-frontend(+0xc275a5)[0x56094977c5a5]

💣 Program crashed: Illegal instruction at 0x00007f51d7ca72ad

Thread 0 "swift-frontend" crashed:

0 0x00007f51d7ca72ad InputStream.streamError.getter + 77 in libFoundation.so

Illegal instruction (core dumped)

After some light digging, it appears that the root is that CFReadStreamCopyError is marked as returning CFError instead of CFError? even though it can return nil. Either that or the root cause is #4348.

@gemini-angelfish
Copy link

gemini-angelfish commented Apr 4, 2024

Can confirm this still happens using the 5.9.2-jammy image, with the same setup as @alanfalloon
Note that this crash does NOT happen on native macOS.

I'm encountering the issue specifically with Alamofire. Alamofire is not officially supported on Linux, but everything that I use works fine except for Multipart requests (as they hit this same crash)

The same tests work perfectly on macOS. The Linux use case is only even relevant as our CI runs on Linux.

Just wanted to document in case any other Alamofire-on-Linux folk run into this.

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

4 participants