From 3fe529ea3bb9f93b451d8405814cf8efda086ac8 Mon Sep 17 00:00:00 2001 From: Wood Date: Mon, 9 Mar 2026 10:31:16 +0800 Subject: [PATCH] fix: clamp inner_index (i64) to i32 range when computing current_inner_idx Avoid overflow/truncation when inner_index is outside i32 range in both gRPC and standard instruction parsing paths. Made-with: Cursor --- src/streaming/event_parser/core/event_parser.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/streaming/event_parser/core/event_parser.rs b/src/streaming/event_parser/core/event_parser.rs index 0c64eb0..5ac8601 100644 --- a/src/streaming/event_parser/core/event_parser.rs +++ b/src/streaming/event_parser/core/event_parser.rs @@ -407,7 +407,8 @@ impl EventParser { // 超低延迟:顺序执行,避免 thread::scope 的 spawn/join 开销 let mut inner_instruction_event: Option = None; if let Some(inner_instructions_ref) = inner_instructions { - let current_inner_idx = inner_index.unwrap_or(-1) as i32; + let raw = inner_index.unwrap_or(-1); + let current_inner_idx = raw.clamp(i32::MIN as i64, i32::MAX as i64) as i32; for (idx, inner_instruction) in inner_instructions_ref.instructions.iter().enumerate() { if (idx as i32) <= current_inner_idx { @@ -566,8 +567,9 @@ impl EventParser { // 当 inner_index 有值时,只查找索引大于当前 inner_index 的 CPI log let mut inner_instruction_event: Option = None; if let Some(inner_instructions_ref) = inner_instructions { - let current_inner_idx = inner_index.unwrap_or(-1) as i32; - + let raw = inner_index.unwrap_or(-1); + let current_inner_idx = raw.clamp(i32::MIN as i64, i32::MAX as i64) as i32; + // 并行执行两个任务: 解析 inner event 和提取 swap_data let (inner_event_result, swap_data_result) = std::thread::scope(|s| { let inner_event_handle = s.spawn(|| {