seq=66473 六項阻擋Rev-10 逐項修妥 @A25 seq=66473 指出的 6 項阻擋,並以 g++ -std=c++17 -O2 -g
-fsanitize=address,undefined -Wall -Wextra -Werror 全量編譯 + 91 項正負向測試 + 60,000 幀變異 fuzz 驗證。
舊式 pos + len > end 界限比較殘留 0 處、cvd_buy/cvd_sell 引用殘留 0 處、
DealStatistics/TickItem 的 wire type 已按 libCorePB.so 逐欄鎖死。
核心結論:本版不再有任何「半可信」路徑——要麼整幀可信地入帳,要麼整幀丟棄並留痕。
077f7a5a…c30ebb59a2121c…d5fb05b6pos+len > end 殘留| 項目 | Rev-9 問題 | Rev-10 修法 | 對應測試 |
|---|---|---|---|
| #1 無號溢位越界 | pos + len > end(43 處,len 為 uint64 時可回繞,檢查形同虛設) | 全檔改 pb_has_bytes(pos, end, need):先證 pos <= end,再以減法 need <= end - pos 比較,永不回繞。舊式比較殘留 0 處。 | T01(UINT64_MAX 長度前綴)、T02(截斷/尾隨垃圾/group wire type)、T16(60,000 幀變異 + 隨機位元組) |
#2 半提交(continue) | bit=3/5/35 任一解析失敗只 note_malformed 後 continue,同一幀其餘 bit 照樣入帳與寫 log | 整幀 all-or-nothing:先暫存 StagedSec,任一 bit 解析失敗即 return 丟棄整個 envelope;狀態與 JSONL 皆零部分提交。 | T04(@A25 原幀:bit3 合法 + bit35 填充垃圾 → 整幀丟棄、push_orderbook_bit3 日誌行數不變) |
| #3 wire type 未鎖死 | DealStatistics 以泛型 w==0 分支把 varint 當 double 收;TickItem.#4 同時接受 varint(/1e9)與 double;TickItem.#2 被推論成買賣 CVD;#22 字串被 strtod 當成交量 | 依 libCorePB.so 逐欄鎖死:#1..#13 與 TickItem.#4/#7/#8/#16 只收 wire==1 且必須 isfinite;#15 volume_precision 只收 varint;#14 只收子訊息;TickItem.#2 改記原始 tick_type 桶(tick_type_hist[8] + tick_type_other),cvd_buy/cvd_sell 欄位徹底刪除(殘留引用 0 處);字串欄位只計數不再解讀。 | T05/T06/T07/T08(varint 冒充 double、NaN、缺欄位、#14/#15 wire 錯、#22 不再當成交量) |
| #4 空/壞設定檔未解除武裝 | if (n <= 0) return;:0-byte 設定檔直接返回,舊 armed 目標表、mkt 表與 inflight ring 原封不動繼續重試 | 新增 disarm_to_passive_locked():清空 g_targets[]、g_mkt_subs[]、g_req_ring[]、g_req_ring_pos、g_loaded_conf_hash,重置 g_mode=PASSIVE_ONLY,並寫 disarmed_to_passive 事件。open 失敗/0 byte/read < 0/被拒設定/unmapped mkt 全部走同一出口(7 處呼叫)。 | T10(0-byte,含 ring 內 inflight 被清)、T11(檔案不存在)、T12(非法 token)、T13(合法設定仍正常 arm,無誤殺) |
| #5 無獨立驅動 | 逾時重試、熱載、sustained_status 只在後續 SendCommand 或 OnPushKline/ParseFrom* 進來時順帶執行;行情一靜止,req_timeout 永遠不會被收割 | 新增獨立 std::thread + condition_variable 250 ms 定時器(timer_tick_body):每 tick 先取 g_send_step_mu,再跑 sweep/每 5 s 熱載/條件式 paced 訂閱與補拉。SendCommand hook 先檢查 g_in_probe_send 才取同一把鎖,故探針自身重入不會自鎖。行程卸載時 destructor 停鐘。 | T14(完全沒有 SendCommand 流量下,900 ms 內完成 3~4 個 tick,過期 0x1811 被收割、req_timeout 落 log) |
| #6 ABI 解析不誠實 | dl_iterate_phdr 掃描未排除自身映像,且可能把自身符號/近似 vtable 當成真品;無任何「是否真的解析到」的可觀測旗標 | 新增 resolve_foreign_symbol()/scan_foreign_images_cb():以自身 dli_fbase 比對 dlpi_addr 排除本 DSO,且要求 vtable 首槽非空才接受;輸出 abi_live_mask(bit0 QuotePush vptr/bit1 ParseFromArray/bit2 ParseFromString/bit3 SendCommand/bit4 OnPushKline),離線為 0,只有真的解析到外部映像才置位。 | T15(離線 abi_mask==0,且任何情況下都不會回傳本映像內位址) |
| 編號 | 對應 | 驗證內容 | 結果 |
|---|---|---|---|
| T01 | fix#1 | 無號溢位:pos+len 回繞繞過界限檢查、UINT64_MAX 長度前綴 | PASS |
| T02 | fix#1/#2 | 截斷幀、尾隨垃圾位元組、非法 group wire type 全部 fail-closed | PASS |
| T03 | @A25 golden | 官方 fixture 乾淨幀解出 bid1=22130/ask1=22131/exch_ms=1795488000123(值級比對 JSONL) | PASS |
| T04 | fix#2 | bit3 合法 + bit35 垃圾 → 整幀丟棄、零部分入帳、零部分日誌 | PASS |
| T05 | fix#3 | OrderBook #3 以 varint 出現 → 拒收 | PASS |
| T06 | fix#3 | DealStatistics #1..#13 varint/NaN/缺欄、#14/#15 wire 錯 → 全部拒收 | PASS |
| T07 | fix#3 | TickItem #4 varint 拒收;#22 字串不再被當成交量;缺 tick_key/price 拒收 | PASS |
| T08 | fix#3 | 單幀 orderbook+dealstat+tick 端到端:tick_type_hist[2]==2、tick_vol_sum==400、無 CVD | PASS |
| T09 | scope | 非目標 sec_id 整段丟棄、不動狀態 | PASS |
| T10 | fix#4 | 0-byte 設定檔 → 解除武裝,inflight ring 一併清空 | PASS |
| T11 | fix#4 | 設定檔不存在 → 解除武裝 | PASS |
| T12 | fix#4 | 設定檔非法 token → 解除武裝 | PASS |
| T13 | fix#4 反向 | 合法設定仍正常 arm(無誤殺) | PASS |
| T14 | fix#5 | 零 SendCommand 流量下 250 ms 定時器收割逾時並落 log | PASS |
| T15 | fix#6 | 離線 abi_live_mask==0、絕不回傳本映像內位址 | PASS |
| T16 | fuzz | 60,000 幀變異/隨機位元組,ASan+UBSan 零報告 | PASS |
=== A36 Rev-10 ASan/UBSan harness (6 review items from seq=66473) ===
[T15] fix#6 abi_live_mask starts at 0, own DSO excluded
[T01] fix#1 subtraction-only bounds guard
[T02] fix#1/#2 truncated frames fail closed
[T03] @A25 golden frame (clean) decodes to bid=22130 ask=22131
[T04] fix#2 bit=3 OK + bit=35 garbage -> ENTIRE frame dropped
[T05] fix#3 OrderBook #3 as varint rejected
[T06] fix#3 DealStatistics #1..#13 must be wire-1 double
[T07] fix#3 TickItem#4 wire-1 only + honest raw tick_type buckets
[T08] fix#3 end-to-end: orderbook + dealstat + tick in one clean frame
[T09] off-scope security dropped, no state change
[T10] fix#4 0-byte config -> disarm (targets, mkts, inflight ring)
[T11] fix#4 missing/unreadable config -> disarm
[T12] fix#4 rejected config (bad sid token) -> disarm
[T13] sanity: a valid config still arms (no over-disarm)
[T14] fix#5 250 ms timer retries/timeouts with ZERO SendCommand traffic
[T16] fuzz: 60k mutated/random frames, ASan must stay silent
frames accepted=3453 dropped=56547 (no ASan report)
=== 91 checks, 0 failures ===
R10_ASAN_UBSAN_RESULT=PASS
| 檔案 | 大小 | SHA-256 |
|---|---|---|
btc_1m_kline_sub_probe_r10.cpp | 100,423 B | 077f7a5a69c211515854e7b447ef9fc9535eefa6099de8ae2c8613b213c30ebb |
test_r10_asan.cpp | 26,800 B | 59a2121c474139db6c907b1e61fb09d36573b0c2f5f295e3d5737564d5fb05b6 |
同梱內容:btc_1m_kline_sub_probe_r10.cpp(預載 .so 源碼)、
test_r10_asan.cpp(自足 harness,#include 源碼本體,不含外部依賴)、
r10_test_run.log(本次原始輸出)、本 HTML。
g++ -std=c++17 -O2 -g -fsanitize=address,undefined -Wall -Wextra -Werror \
-o /tmp/test_r10 test_r10_asan.cpp
ASAN_OPTIONS=detect_leaks=0 UBSAN_OPTIONS=print_stacktrace=1 /tmp/test_r10 # 期望 R10_ASAN_UBSAN_RESULT=PASS
g++ -std=c++17 -O2 -fPIC -shared -Wall -Wextra -Werror -o /tmp/libbtc_r10.so \
btc_1m_kline_sub_probe_r10.cpp -ldl # 預載用 .so(匯出 4 個 hook)
離線預載煙霧測試(本機實跑):BTC_PROBE_CONF=/tmp/不存在.conf
LD_PRELOAD=/tmp/libbtc_r10.so /bin/true → 退出碼 0,日誌首兩行依序為
disarmed_to_passive(reason=conf_open_failed)與
probe_loaded(ver=r10-a36-66473、abi_mask=0、timer_period_ms=250),
證明「壞設定即時解除武裝」與「定時器已起」在真實預載情境下成立。
/bin/true 預載煙霧測試,
未連接 Futu 行情,LIVE_FUTU_EVIDENCE=NONE。abi_live_mask 離線恆為 0。這是刻意設計:只有真的從外部映像(dlpi_addr ≠ 本 DSO dli_fbase)
解析到符號才置位。若實機上仍為 0,即代表 QuotePush vtable 未被解析,屆時必須回報而非假設可用。@A25 原 fixture 幀在 Rev-10 會被整幀丟棄。該幀的 bit=35 附帶 synthetic-non-orderbook 填充字串,
不是合法的 FTCmdTick.Tick;依 fix#2 的原子規則,同一幀的合法 bit=3 亦一併不採用(T03 用移除該填充項的乾淨幀
驗證解碼值正確,T04 驗證原幀被整幀丟棄)。若 @A25 認為 bit=35 應容錯,需明確裁示優先序——本版選擇「寧可整幀不作數」。TickItem.#2 不含買賣方向。Rev-9 把它當 CVD 買賣推論,Rev-10 只記原始 tick_type 桶;
在 libCorePB.so 語義被證實前,任何「買/賣」二字都不應出現在輸出。