Skip to content

MOD-16653 Prevent more heap overflow + other rdb load asserions (#2086) - #2167

Merged
AvivDavid23 merged 2 commits into
8.4from
cherry-pick-b54cdcef-to-8.4
Sep 14, 2026
Merged

AvivDavid23 merged 2 commits into
8.4from
cherry-pick-b54cdcef-to-8.4

Conversation

@AvivDavid23

@AvivDavid23 AvivDavid23 commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Note

High Risk
Changes the untrusted RDB/RESTORE ingestion path with new validation that rejects previously loadable malicious payloads; incorrect checks could break legitimate dumps or leave gaps in exploit prevention.

Overview
Hardens RESTORE/RDB load for compressed time-series chunks by rejecting inconsistent or attacker-crafted metadata before Gorilla decompression can touch misaligned buffers.

Compressed_LoadFromRDB now fails load when size ≠ actual data length, when size is not 8-byte aligned (matching binary_t word access in gorilla), and when inflated count cannot be supported by idx (using idx/2 < count-1 to avoid overflow on huge count values).

series_rdb_load rejects chunkSizeBytes of 0 or not divisible by 8 at series load time.

Flow tests patch valid DUMP payloads to exercise size/length mismatch, non-aligned buffers, and bogus count values (including near-overflow), expecting Bad data format and no partial key restore.

Reviewed by Cursor Bugbot for commit 25892b0. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 25892b0. Configure here.

Comment thread src/rdb.c
RedisModule_LogIOError(io, "error", "chunkSizeBytes must be a non-zero multiple of 8");
err = true;
return NULL;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Chunk size check misses negative values

Medium Severity

The new chunkSizeBytes guard runs after an unsigned RDB integer is stored in signed long long cCtx.chunkSizeBytes. Values with the high bit set become negative; a negative multiple of 8 still passes == 0 and % 8 != 0, so crafted payloads can skip the check. NewSeries later passes that value to NewChunk as a size_t, which can cause a huge allocation or a crash on a later append.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 25892b0. Configure here.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
40.9% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@gabsow gabsow left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved.

Reviewed mechanically rather than by eyeball: 3-way-applied master b54cdcef onto this base and diffed the result against the PR head, so what I actually reviewed is the human conflict resolution.

  • src/compressed_chunk.c and src/rdb.c hunks are byte-identical to master.
  • The follow-up commit test: assert corrupted DUMP restore errors strengthens the tests relative to master: .error() → .error().contains("Bad data format") on all three new tests, and the hard-coded RDB payload replaced by one generated from a live DUMP. Nothing weakened anywhere in the stack.
  • This branch's series_rdb_save field order matches the test's manual RDB parser; compressed-chunk field order and SERIES_OPT_COMPRESSED_GORILLA == 2 confirmed on-branch.
  • No conflict markers, the test file byte-compiles, and all five _rdb_* helpers are defined exactly once.

Red legs, neither caused by this change:

  • build-linux-x64 / x64-bullseye — infra. Debian 11 moved to archive, so deb.debian.org/debian-security bullseye-security 404s for every package. Branch-independent; it reddens every open PR until CI pins archive.debian.org or drops bullseye.
  • SonarCloud — 40.9% Duplication on New Code (gate requires ≤3%), from the ~45-line field-walking preamble shared by _patch_first_compressed_chunk_misalign_size and _patch_first_compressed_chunk_count. Inherited from #2086, not introduced here.

Non-blocking follow-up: master #2086 still carries the hard-coded payload and the bare .error(), so master is now behind its own backports. Worth forward-porting the follow-up commit so the next sync doesn't conflict.

Note the rest of CI is still running as I approve; I'm watching the stack and will flag any red leg that isn't red on its own base branch.

@AvivDavid23
AvivDavid23 merged commit 46e8242 into 8.4 Sep 14, 2026
55 of 58 checks passed
@AvivDavid23
AvivDavid23 deleted the cherry-pick-b54cdcef-to-8.4 branch September 14, 2026 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants