Project
vgrep
Description
The search code multiplies max_results by 3 for reranking purposes, but this multiplication can overflow for large values, causing panic in debug mode or incorrect behavior in release mode.
Error Observation
With large max_results values, the multiplication overflows.
Error Message
thread 'main' panicked at 'attempt to multiply with overflow'
Debug Logs
System Information
Version: 0.1.0
## Operating System
OS: Ubuntu 24.04.3 LTS
Kernel: 6.8.0-79-generic
Arch: x86_64
## Hardware
CPU: AMD Ryzen 9 5950X 16-Core Processor (4 cores)
RAM: 11 GB
## Build Environment
Rust: rustc 1.92.0 (ded5c06cf 2025-12-08)
Target: x86_64
Screenshots
No response
Steps to Reproduce
- Open
src/core/search.rs line 51:
let candidates = self
.db
.search_similar(&query_embedding, &abs_path, max_results * 3)?; // OVERFLOW!
- Open
src/core/db.rs line 197:
results.truncate(limit * 3); // Get more for reranking - OVERFLOW!
- Set
max_results = 6148914691236517206 (usize::MAX / 3 + 1)
- Observe overflow panic or wrapping behavior
Expected Behavior
Should use checked_mul or saturating_mul to prevent overflow.
Actual Behavior
Panic in debug mode; silent wraparound producing wrong results in release mode.
Additional Context
No response
Project
vgrep
Description
The search code multiplies
max_resultsby 3 for reranking purposes, but this multiplication can overflow for large values, causing panic in debug mode or incorrect behavior in release mode.Error Observation
With large max_results values, the multiplication overflows.
Error Message
Debug Logs
System Information
Screenshots
No response
Steps to Reproduce
src/core/search.rsline 51:src/core/db.rsline 197:max_results = 6148914691236517206(usize::MAX / 3 + 1)Expected Behavior
Should use checked_mul or saturating_mul to prevent overflow.
Actual Behavior
Panic in debug mode; silent wraparound producing wrong results in release mode.
Additional Context
No response