Skip to content

[bug] 崩溃报告:空指针访问导致应用崩溃 #2383

@danbao

Description

@danbao

📋 基本信息

  • 应用版本: 3.0.36 (Build 189)
  • Bundle ID: com.reqable.macosx
  • 平台: macOS 26.2 (25C56)
  • 设备型号: Mac16,10 (Apple Silicon)
  • 崩溃时间: 2026-01-25 03:30:09 +0800
  • 启动时间: 2026-01-23 07:55:01 +0800
  • 运行时长: ~43.5 小时后崩溃

🔴 崩溃概要

应用在 Flutter UI 线程中发生了空指针访问崩溃(Segmentation Fault)。

异常类型

Exception Type:    EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000000
Exception Codes:   0x0000000000000001, 0x0000000000000000
Termination Reason: Namespace SIGNAL, Code 11, Segmentation fault: 11

崩溃线程

Thread 2: io.flutter.ui (崩溃线程)

📍 崩溃堆栈

Thread 2 Crashed:: io.flutter.ui
0   libreqable_netbare.dylib      netbareHttpPayloadTypeGet + 4
1   App                           0x11c2e1938 (offset: 22840)
2   App                           0x11ced1790 (offset: 12539792)
3   App                           0x11cee1450 (offset: 12604496)
4   App                           0x11cee0334 (offset: 12600116)
5   App                           0x11d046830 (offset: 14067760)
6   App                           0x11cecebf8 (offset: 12528632)
7   App                           0x11cece154 (offset: 12525908)
8   App                           0x11d0276f8 (offset: 13940472)
9   App                           0x11cd420b0 (offset: 10903728)
10  App                           0x11cd160ac (offset: 10723500)
11  App                           0x11cd15d78 (offset: 10722680)
12  App                           0x11c339e4c (offset: 384588)
13  App                           0x11c33a6f0 (offset: 386800)
14  App                           0x11d0608bc (offset: 14174396)
15  App                           0x11c2f2a0c (offset: 92684)
16  App                           0x11c2e3fb4 (offset: 32692)
17  FlutterMacOS                  dart::DartEntry::InvokeFunction(...)
18  FlutterMacOS                  dart::DartLibraryCalls::HandleMessage(...)

🔍 根本原因分析

1. 崩溃位置

崩溃发生在 libreqable_netbare.dylibnetbareHttpPayloadTypeGet 函数中,偏移量仅为 +4 字节,说明函数刚开始执行就崩溃了。

2. 寄存器状态

x8: 0x0000000000000000   <- 空指针
pc: 0x0000000104bc9514   <- 程序计数器
far: 0x0000000000000000  <- 访问的错误地址为 0x0
esr: 0x92000006 (Data Abort) byte read Translation fault

寄存器 x8 为 0,并且尝试从地址 0x0 读取数据导致崩溃。

3. 可能的原因

  • netbareHttpPayloadTypeGet 函数接收了一个空指针参数
  • 函数内部没有进行空指针检查就直接解引用
  • 调用方传递了无效的对象引用

💡 重现步骤

由于应用运行了约 43.5 小时后才崩溃,这可能是:

  1. 长时间运行后的内存管理问题
  2. 特定网络请求处理场景触发
  3. HTTP payload 类型判断时的边界条件

暂时无法确定具体重现步骤,需要更多信息。

🔧 建议修复方案

1. 立即修复(Critical)

netbareHttpPayloadTypeGet 函数中添加空指针检查:

// 在 libreqable_netbare.dylib 中
PayloadType netbareHttpPayloadTypeGet(HttpPayload* payload) {
    // 添加空指针检查
    if (payload == nullptr) {
        // 记录错误日志
        // 返回默认值或错误码
        return PAYLOAD_TYPE_UNKNOWN;
    }
    
    // 原有逻辑
    return payload->type;
}

2. 调用方检查

检查所有调用 netbareHttpPayloadTypeGet 的地方,确保传递的参数有效:

// 在 Dart/Flutter 代码中
void handleHttpPayload(dynamic payload) {
    if (payload == null) {
        // 提前返回或处理
        return;
    }
    
    final type = netbareHttpPayloadTypeGet(payload);
    // ...
}

3. 增强日志

在崩溃前添加更多日志,帮助定位问题:

  • 记录 HTTP 请求的详细信息
  • 记录 payload 对象的创建和销毁
  • 添加内存使用监控

📊 影响范围

  • 严重程度: 🔴 Critical(导致应用完全崩溃)
  • 影响版本: 3.0.36 (可能更早版本也存在)
  • 影响平台: macOS (Apple Silicon)
  • 触发频率: 未知(需要长时间运行)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions