fix(journal): improve journal file access error handling and validation - #22310
Conversation
There was a problem hiding this comment.
No issues found across 1 file
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Architecture diagram
sequenceDiagram
participant RE as RRDEngine
participant J2 as JournalV2 (mmap)
participant Mem as Protected Memory Area
participant Log as Logger
Note over RE, Mem: Retention Scan: find_uuid_first_time loop
RE->>J2: NEW: journalfile_v2_data_acquire_with_hint()
J2-->>RE: Return j2_header pointer & NEW: journal_v2_file_size
alt Header acquisition failed
RE->>RE: Skip to next datafile
end
RE->>RE: PROTECTED_ACCESS_SETUP (mmap guards)
alt Access Signal (SIGBUS/SIGSEGV) or no_signal_received is false
RE->>Log: CHANGED: "failed to access journalfile"
else Access Successful
RE->>Mem: CHANGED: Read header fields (start_time, offsets, count)
Note over RE: NEW: Strict Bounds Validation
RE->>RE: Check __builtin_mul_overflow(metric_count, size)
alt NEW: Validation Error (Offset/Size > File Size)
RE->>Log: NEW: "metric list exceeds journal file size"
RE->>RE: Set journal_access_failed = true
else Validation Success
loop For each UUID entry
RE->>RE: NEW: Check if journal_search_start >= metric_count
RE->>Mem: Access uuid_list[index]
Note right of Mem: Binary search or direct access
end
end
end
RE->>J2: journalfile_v2_data_release()
opt NEW: Access Failure skip
RE->>RE: Skip early-release logic
RE->>RE: Continue to next datafile
end
RE->>RE: datafile_release_and_acquire_next_for_retention()
There was a problem hiding this comment.
Pull request overview
This PR adjusts rrdengine’s journal v2 scanning so journal header fields are accessed only after PROTECTED_ACCESS_SETUP, and adds additional bounds validation when walking the journal metric list (to better handle corrupted/unreadable journal files).
Changes:
- Pass
data_sizetojournalfile_v2_data_acquire_with_hint()and use it for validating metric-list bounds. - Move journal header reads (
start_time_ut,metric_offset,metric_count) underPROTECTED_ACCESS_SETUP. - Add guard logic for running past
metric_countand skip journals when protected access / validation fails.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Improves robustness of journal v2 file access during retention scanning by performing header/metric list validation under protected access and skipping truncated/invalid journals safely.
Changes:
- Read header fields only after
PROTECTED_ACCESS_SETUPand treat protection failures as access failures. - Validate
metric_offset/metric_countagainst the journal file size using overflow-safe arithmetic and skip invalid files. - Guard against
journal_search_start >= journal_metric_countto avoid invalid indexing.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Hardens journal v2 access during DBENGINE retention scanning by moving header-derived reads under protected access and validating metric directory bounds against the mapped file size to avoid out-of-bounds access on truncated/corrupt journals.
Changes:
- Acquire journal v2 mapped size via
journalfile_v2_data_acquire_with_hint()and validatemetric_offset/metric_countwith overflow-safe arithmetic before indexing. - Read header fields (
start_time_ut,metric_offset,metric_count) only underPROTECTED_ACCESS_SETUPand treat access faults as “skip and continue”. - Add guard for
journal_search_start >= journal_metric_countto prevent invalid indexing during the scan loop.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
thiagoftsm
left a comment
There was a problem hiding this comment.
No issues found during runtime, LGTM!



Summary
Summary by cubic
Hardened journal file access in the retention scan and simplified the search loop to avoid invalid indexing. Prevents out-of-bounds reads and cleanly skips truncated or invalid journals.
journalfile_v2_data_acquire_with_hintand validatemetric_offset/metric_countwith overflow-safe bounds; skip when the metric list would exceed the file.PROTECTED_ACCESS_SETUP; handle mmap/protection failures.journal_search_start >= journal_metric_count.Written for commit 7870cb2. Summary will update on new commits. Review in cubic