{"record":{"id":"a86c2c952fe4051f","repo":"Tencent/matrix","slug":"fatal-error-s","errorCode":null,"errorMessage":"fatal error: %s\n","messagePattern":"fatal error: (.+?)\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"matrix/matrix-iOS/Matrix/WCCrashBlockMonitor/KSCrash/swift/Basic/Demangle.cpp","lineNumber":42,"sourceCode":"#include \"Demangle.h\"\n#include \"Fallthrough.h\"\n#include \"SwiftStrings.h\"\n#include \"LLVM.h\"\n#include \"Punycode.h\"\n//#include \"UUID.h\"\n#include \"Optional.h\"\n#include \"StringRef.h\"\n#include <functional>\n#include <inttypes.h>\n#include <vector>\n#include <cstdio>\n#include <cstdlib>\n\nusing namespace swift;\nusing namespace Demangle;\n\n[[noreturn]] static void unreachable(const char *Message) {\n    fprintf(stderr, \"fatal error: %s\\n\", Message);\n    std::abort();\n}\n\nDemanglerPrinter &DemanglerPrinter::operator<<(unsigned long long n) & {\n    char buffer[32];\n    snprintf(buffer, sizeof(buffer), \"%\" PRIu64, n);\n    Stream.append(buffer);\n    return *this;\n}\nDemanglerPrinter &DemanglerPrinter::operator<<(long long n) & {\n    char buffer[32];\n    snprintf(buffer, sizeof(buffer), \"%\" PRId64, n);\n    Stream.append(buffer);\n    return *this;\n}\n\nnamespace {\nstruct QuotedString {","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-iOS/Matrix/WCCrashBlockMonitor/KSCrash/swift/Basic/Demangle.cpp#L24-L60","documentation":"swift::Demangle::unreachable() is the Demangler's internal 'impossible state' handler: it prints 'fatal error: <Message>' to stderr and calls std::abort(). The demangler calls it whenever a Node or encoded mangled-name structure violates invariants the demangler believes cannot occur, e.g. Node destructors on unexpected node kinds, or demangling paths for specializations, metatype representations, or impl parameter/result encodings that don't match expected shapes.","triggerScenarios":"Parsing a corrupted or malformed Swift mangled symbol name that reaches an unsupported encoding path (demangleFuncSigSpecializationConstantProp, demangleMetatypeRepresentation, demangleImplParameterOrResult, isSimpleType), or a demangler bug while freeing/printing Node structures.","commonSituations":"Crash reporting symbolication (KSCrash CrashBlockMonitor) demangling stack frames from an unstripped Swift binary compiled by a different Swift version than the bundled demangler; hand-crafted or truncated symbol names fed to the demangler.","solutions":["Match the demangler version to the Swift compiler version that produced the mangled names (sync KSCrash's Demangle.cpp with the app's Swift toolchain)","Validate/sanitize symbol names before demangling; skip symbols that don't start with the expected Swift mangling prefix","Update KSCrash/Matrix to a version with the demangler fix for that message","If reproducible, report the demangling crash to swift/KSCrash upstream with the offending symbol"],"exampleFix":"// before\nconst char *mangled = symbol;\nstd::string demangled = swift::Demangle::demangleSymbolAsString(mangled);\n// after\nif (symbol && strncmp(symbol, \"$s\", 2) == 0) {\n  std::string demangled = swift::Demangle::demangleSymbolAsString(symbol);\n} else {\n  const char *demangled = symbol; // leave undemangled\n}","handlingStrategy":"type-guard","validationCode":"bool isSwiftMangled(const char *s) { return s && (strncmp(s, \"$s\", 2) == 0 || strncmp(s, \"_T0\", 3) == 0); }","typeGuard":"static inline bool safeToDemangle(const char *symbol) {\n  return symbol != nullptr && isSwiftMangled(symbol) && strlen(symbol) < 4096;\n}","tryCatchPattern":"// demangler abort()s; cannot catch, so guard inputs and isolate:\nif (safeToDemangle(sym)) {\n  demangled = demangle(sym);\n} else {\n  demangled = sym; // fallback to raw symbol\n}","preventionTips":["Keep the bundled demangler in sync with the app's Swift toolchain version","Never feed arbitrary/truncated strings to the demangler; verify mangling prefixes","Pin KSCrash/Matrix versions known-good with your Xcode/Swift version","Fuzz or smoke-test symbolication after Swift version upgrades"],"tags":["swift","demangler","abort","symbolication","crash-reporting"],"backgroundTag":"internal-invariant-violation","analyzedSha":"3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7","analyzedAt":"2026-09-08T08:01:39.722Z","contentChangedAt":"2026-09-08T08:01:39.722Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}