Skip to content

fix(dbengine): validate extent disk size and fix uncompressed page bounds - #22324

Merged
stelfrag merged 3 commits into
netdata:masterfrom
stelfrag:fix_invalid_extent_metadata
May 2, 2026
Merged

fix(dbengine): validate extent disk size and fix uncompressed page bounds#22324
stelfrag merged 3 commits into
netdata:masterfrom
stelfrag:fix_invalid_extent_metadata

Conversation

@stelfrag

@stelfrag stelfrag commented Apr 30, 2026

Copy link
Copy Markdown
Collaborator
Summary
  • Add rrdeng_valid_extent_disk_size() and check at journal restore, open-cache add, and disk read.
  • Fix missing bounds check in the uncompressed page path that could read past payload_length on corrupt extent metadata.
  • Treat short reads from uv_fs_read as errors.

Summary by cubic

Validates extent disk sizes across restore/open/read/flush paths and strengthens page boundary checks to prevent overreads on corrupt metadata. Short or partial uv_fs_read results are treated as errors, with clearer logs for invalid extents.

  • Bug Fixes
    • Added rrdeng_valid_extent_disk_size() with min/max helpers; enforced at journal restore, open-cache add, extent flush, and disk reads; improved logging when skipping invalid extents.
    • Hardened page offset/length validation for both uncompressed and decompressed paths; skip and count invalid pages instead of reading out of bounds.
    • CRC now calculated over data_length - trailer; reject mismatched checksums.
    • Treat negative or short uv_fs_read returns as errors; free buffers and mark I/O error.

Written for commit 138338f. Summary will update on new commits. Review in cubic

…unds

Add rrdeng_valid_extent_disk_size() and check at journal restore, open-cache
add, and disk read. Fix missing bounds check in the uncompressed page path that could read past payload_length on corrupt extent metadata. Treat short reads from uv_fs_read as errors.
@stelfrag
stelfrag marked this pull request as ready for review April 30, 2026 06:35
@stelfrag
stelfrag requested a review from thiagoftsm as a code owner April 30, 2026 06:35
Copilot AI review requested due to automatic review settings April 30, 2026 06:35
@stelfrag
stelfrag requested a review from vkalintiris as a code owner April 30, 2026 06:35
@stelfrag
stelfrag marked this pull request as draft April 30, 2026 06:35
@stelfrag
stelfrag removed the request for review from vkalintiris April 30, 2026 06:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens DBEngine extent handling by validating extent sizes at multiple ingestion/read points, tightening bounds checks in the uncompressed-page path, and treating short disk reads as I/O errors to better handle corrupt on-disk metadata.

Changes:

  • Add rrdeng_valid_extent_disk_size() (min/max helpers) and enforce it during journal restore, open-cache insertion, and extent reads.
  • Fix missing bounds check for uncompressed pages to prevent reading past payload_length on corrupt extent metadata.
  • Treat short reads from uv_fs_read() as errors (not just -1).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/database/engine/rrdengine.h Introduces min/max extent disk size helpers and a shared validator.
src/database/engine/rrdengine.c Adds an internal invariant check for flushed extent sizes and braces around open-cache insertion.
src/database/engine/pdc.c Uses the new size validator, fixes CRC length source, adds uncompressed bounds check, validates extent reads, and treats short reads as errors.
src/database/engine/pagecache.c Prevents adding open-cache entries for invalid extent sizes (with logging).
src/database/engine/journalfile.c Validates extent_size during journal restore to reject corrupted transactions earlier.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/database/engine/pagecache.c Outdated
Comment thread src/database/engine/pdc.c Outdated
@stelfrag
stelfrag requested a review from Copilot April 30, 2026 09:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds validation and safety checks around on-disk extent sizes and page payload boundaries to prevent invalid reads and improve error handling for corrupted metadata / short I/O.

Changes:

  • Introduces rrdeng_valid_extent_disk_size() and enforces it across restore, open-cache, flush, and disk read paths.
  • Adds missing bounds checks for uncompressed page loads to avoid over-reading past payload_length.
  • Treats short uv_fs_read() reads as errors (not just -1).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/database/engine/rrdengine.h Adds min/max helpers and a shared extent size validator.
src/database/engine/rrdengine.c Validates flushed extent size before adding pages to open cache.
src/database/engine/pdc.c Validates extent size, fixes CRC length basis, adds uncompressed payload bounds checks, and treats short reads as errors.
src/database/engine/pagecache.c Skips adding open-cache pages for invalid extent sizes with rate-limited logs.
src/database/engine/journalfile.c Validates extent_size during journal restore to reject corrupted payloads.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/database/engine/pdc.c Outdated
Comment thread src/database/engine/pdc.c
@sonarqubecloud

Copy link
Copy Markdown

@stelfrag
stelfrag requested a review from Copilot April 30, 2026 09:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Improves rrdengine robustness against corrupt extent metadata by validating on-disk extent sizes across multiple paths, tightening page bounds checks to avoid overreads, and treating partial reads as I/O errors.

Changes:

  • Added rrdeng_valid_extent_disk_size() helpers and enforced them during journal restore, open-cache insertion, extent flush, and disk reads.
  • Fixed missing bounds checks in the uncompressed page path to prevent reads past payload_length.
  • Treated short uv_fs_read() results as errors and adjusted CRC calculation length.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/database/engine/rrdengine.h Adds min/max/valid helpers for extent disk size.
src/database/engine/rrdengine.c Validates flushed extent sizes and guards open-cache additions.
src/database/engine/pdc.c Validates extent sizes on read, fixes CRC length, strengthens page bounds checks, and treats short reads as errors.
src/database/engine/pagecache.c Skips adding open-cache pages for invalid extent sizes.
src/database/engine/journalfile.c Validates extent size during journal restore to reject corrupted transactions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/database/engine/rrdengine.h
Comment thread src/database/engine/rrdengine.c
Comment thread src/database/engine/pdc.c
Comment thread src/database/engine/pdc.c

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Improves robustness of the DBEngine extent read/restore/open-cache pipeline by validating on-disk extent sizes, tightening page payload bounds checks (especially for uncompressed extents), and treating short disk reads as I/O errors to avoid parsing incomplete/corrupt data.

Changes:

  • Add rrdeng_valid_extent_disk_size() (min/max helpers) and enforce it in journal restore, open-cache insertion, disk reads, and (internally) after extent flush.
  • Harden extent parsing by fixing CRC coverage length and adding missing bounds checks for the uncompressed-page path to prevent payload overreads on corrupt metadata.
  • Treat partial uv_fs_read() results as failures (not just negative returns), freeing buffers and marking I/O errors.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/database/engine/rrdengine.h Adds reusable min/max size helpers and a centralized extent-size validator.
src/database/engine/rrdengine.c Adds an internal assertion to catch invalid extent sizes immediately after flush (debug/internal-checks aid).
src/database/engine/pdc.c Uses extent-size validation during parsing and reads; fixes CRC length; adds missing bounds checks for uncompressed pages; treats short reads as errors.
src/database/engine/pagecache.c Skips adding open-cache entries for extents with invalid on-disk size (with rate-limited logging).
src/database/engine/journalfile.c Rejects journal restore payloads that reference extents with invalid size.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@stelfrag
stelfrag marked this pull request as ready for review May 1, 2026 11:48

@thiagoftsm thiagoftsm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

After almost two hours running, no issues were found with data and netdata. LGTM!

@stelfrag
stelfrag merged commit 1608f65 into netdata:master May 2, 2026
166 checks passed
@stelfrag
stelfrag deleted the fix_invalid_extent_metadata branch May 2, 2026 18:05
@stelfrag stelfrag mentioned this pull request Jun 22, 2026
Ferroin pushed a commit that referenced this pull request Jul 15, 2026
…unds (#22324)

* fix(dbengine): validate extent disk size and fix uncompressed page bounds

Add rrdeng_valid_extent_disk_size() and check at journal restore, open-cache
add, and disk read. Fix missing bounds check in the uncompressed page path that could read past payload_length on corrupt extent metadata. Treat short reads from uv_fs_read as errors.

* fix(dbengine): improve logging for invalid extent size handling

* fix(pdc): enhance boundary checks for page offsets and lengths

(cherry picked from commit 1608f65)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants