Skip to content

Conversation

@hengfeiyang
Copy link
Contributor

@hengfeiyang hengfeiyang commented Dec 1, 2025

fixed #9406

@github-actions github-actions bot added the ☢️ Bug Something isn't working label Dec 1, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Dec 1, 2025

Failed to generate code suggestions for PR

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 1, 2025

Greptile Overview

Greptile Summary

Fixed critical array index out-of-bounds panic in create_wal_dir_datetime_filter when processing WAL directory paths with December dates.

  • Root cause: month_days[month as usize] used 1-indexed month value (1-12) to index 0-indexed array (0-11), causing panic when month=12
  • Fix: Changed to month_days[(month - 1) as usize] to correctly map month values to array indices
  • Impact: This prevents runtime panics during WAL searches for any files in December directories

Minor suggestion: leap year calculation could be more accurate by accounting for century rules.

Confidence Score: 4/5

  • This PR is safe to merge with minimal risk - fixes a critical bug with a simple, correct solution
  • The fix correctly addresses an off-by-one array indexing bug that caused panics. The solution is minimal and appropriate. Score is 4 instead of 5 due to a minor style suggestion about leap year calculation accuracy, though the existing simplified logic is acceptable for the use case.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
src/config/src/utils/async_file.rs 4/5 Fixed array index off-by-one bug that caused panic for December (month=12); leap year logic could be more accurate

Sequence Diagram

sequenceDiagram
    participant Caller
    participant create_wal_dir_datetime_filter
    participant Filter Closure
    participant month_days Array

    Caller->>create_wal_dir_datetime_filter: start_time, end_time, extension_pattern, skip_count
    create_wal_dir_datetime_filter->>Filter Closure: creates closure
    
    loop For each path
        Caller->>Filter Closure: path (e.g., files/org/stream/2024/12/01/12/)
        Filter Closure->>Filter Closure: parse year from path (e.g., 2024)
        Filter Closure->>Filter Closure: parse month from path (e.g., 12)
        
        alt Month parsing succeeds
            Filter Closure->>month_days Array: access [(month - 1) as usize]
            Note over Filter Closure,month_days Array: Fixed: month=12 now maps to index 11<br/>Previously: month=12 caused panic at index 12
            month_days Array-->>Filter Closure: returns days (31)
            Filter Closure->>Filter Closure: apply leap year adjustment if month==2
            Filter Closure->>Filter Closure: parse day and validate against days
            Filter Closure->>Filter Closure: parse hour and validate
            Filter Closure->>Filter Closure: check datetime range
            Filter Closure-->>Caller: true/false
        else Month parsing fails
            Filter Closure-->>Caller: uses start_time.month() as default
        end
    end
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@oasisk oasisk merged commit 1734f63 into main Dec 1, 2025
49 of 53 checks passed
@oasisk oasisk deleted the fix/search-wal branch December 1, 2025 03:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

☢️ Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Panic] index out of bounds in async_file.rs:202 when querying logs (v0.20.0-rc2)

3 participants