Skip to content

Diagnostics Logger crashes when a message is over 16384 characters and contains unicode characters. #181

@michaelversus

Description

@michaelversus

Hello,

We're experiencing a crash when using the Diagnostics Logger and try to write a message that is over 16384 characters and contain unicode characters.
More specifically the library crashes on the assertionFailure "Invalid data is logged" in DiagnosticsLogger.handleLoggedData

To trigger the crash, please create an iOS app , initialize the library and run

        let str = (1...8192).map { _ in "α" }.joined(separator: "")
        print("1" + str)

What this does, is that it prints a string that consists of the number "1" and the greek character "α" (unicode 0x03B1, utf-8: 0xCE 0xB1). The resulting string is printed on the stdout and is 16385 characters long. However, the app tries to convert the first 16384 characters to unicode, which isn't possible, as the last byte of the last "α" is missing from the buffer. So, the assertion is triggered and the library crashes with the debug configuration. On a 'release' configuration, the app will not crash, but the logs will be lost.

Stack trace:

#0 0x0000000194f64024 in swift_runtime_on_report ()
#1 0x000000019501cc64 in swift_stdlib_reportFatalErrorInFile ()
#2 0x0000000194c9dd50 in Swift.assertionFailure(: Swift.StaticString, : Swift.String, file: Swift.StaticString, line: Swift.UInt, flags: Swift.UInt32) -> Swift.Never ()
#3 0x0000000194c9dfd0 in Swift.assertionFailure(
: @autoclosure () -> Swift.String, file: Swift.StaticString, line: Swift.UInt) -> () ()
#4 0x00000001046707d0 in closure #1 in closure #1 in DiagnosticsLogger.handleLoggedData(
:) at /Users/a.koxaras-si/Library/Developer/Xcode/DerivedData/DiagnosticsPlayground-goevnajoyrykgwexgfjwlinnqbsh/SourcePackages/checkouts/Diagnostics/Sources/Logging/DiagnosticsLogger.swift:268
#5 0x0000000104671808 in partial apply for closure #1 in closure #1 in DiagnosticsLogger.handleLoggedData(
:) ()
#6 0x00000001cbd22c88 in ObjectiveC.autoreleasepool<τ_0_0>(invoking: () throws -> τ_0_0) throws -> τ_0_0 ()
#7 0x00000001046705dc in closure #1 in DiagnosticsLogger.handleLoggedData(:) at /Users/a.koxaras-si/Library/Developer/Xcode/DerivedData/DiagnosticsPlayground-goevnajoyrykgwexgfjwlinnqbsh/SourcePackages/checkouts/Diagnostics/Sources/Logging/DiagnosticsLogger.swift:264
#8 0x000000010467063c in partial apply for closure #1 in DiagnosticsLogger.handleLoggedData(
:) ()
#9 0x0000000104696bec in closure #1 in static ExceptionCatcher.catch<()>(callback:) at /Users/a.koxaras-si/Library/Developer/Xcode/DerivedData/DiagnosticsPlayground-goevnajoyrykgwexgfjwlinnqbsh/SourcePackages/checkouts/ExceptionCatcher/Sources/ExceptionCatcher/ExceptionCatcher.swift:36
#10 0x0000000104696cf8 in thunk for @callee_guaranteed () -> () ()
#11 0x0000000104696d50 in thunk for @escaping @callee_guaranteed () -> () ()
#12 0x00000001046970ac in +[ExceptionCatcher catchException:error:] at /Users/a.koxaras-si/Library/Developer/Xcode/DerivedData/DiagnosticsPlayground-goevnajoyrykgwexgfjwlinnqbsh/SourcePackages/checkouts/ExceptionCatcher/Sources/ExceptionCatcherInternal/ExceptionCatcher.m:7
#13 0x000000010469687c in static ExceptionCatcher.catch<()>(callback:) at /Users/a.koxaras-si/Library/Developer/Xcode/DerivedData/DiagnosticsPlayground-goevnajoyrykgwexgfjwlinnqbsh/SourcePackages/checkouts/ExceptionCatcher/Sources/ExceptionCatcher/ExceptionCatcher.swift:34
#14 0x00000001046701e0 in DiagnosticsLogger.handleLoggedData(
:) at /Users/a.koxaras-si/Library/Developer/Xcode/DerivedData/DiagnosticsPlayground-goevnajoyrykgwexgfjwlinnqbsh/SourcePackages/checkouts/Diagnostics/Sources/Logging/DiagnosticsLogger.swift:263
#15 0x00000001046700ac in closure #1 in DiagnosticsLogger.setupPipe() at /Users/a.koxaras-si/Library/Developer/Xcode/DerivedData/DiagnosticsPlayground-goevnajoyrykgwexgfjwlinnqbsh/SourcePackages/checkouts/Diagnostics/Sources/Logging/DiagnosticsLogger.swift:249
#16 0x0000000104670414 in thunk for @escaping @callee_guaranteed @sendable (@guaranteed NSFileHandle) -> () ()
#17 0x0000000180e6d0dc in __33-[NSConcreteFileHandle _monitor:]_block_invoke ()
#18 0x000000010459e5d0 in _dispatch_client_callout ()
#19 0x00000001045a1a80 in _dispatch_continuation_pop ()
#20 0x00000001045b744c in _dispatch_source_invoke ()
#21 0x00000001045a667c in _dispatch_lane_serial_drain ()
#22 0x00000001045a7628 in _dispatch_lane_invoke ()
#23 0x00000001045b42cc in _dispatch_root_queue_drain_deferred_wlh ()
#24 0x00000001045b3838 in _dispatch_workloop_worker_thread ()
#25 0x00000001051c6bcc in _pthread_wqthread ()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions