Skip to content

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

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

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

Conversation

@AvivDavid23

@AvivDavid23 AvivDavid23 commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Note

High Risk
Changes sit on the untrusted RDB/RESTORE input path; incorrect validation could break legitimate restores, but the edits are additive rejections of malformed metadata rather than new decode logic.

Overview
Hardens RESTORE/RDB loading against crafted DUMP payloads that could previously pass partial checks and trigger heap issues in Gorilla decompression.

Compressed_LoadFromRDB now rejects compressed chunks when size ≠ loaded buffer length, when size is not 8-byte aligned (Gorilla word access), and when count is inconsistent with idx using idx/2 < count - 1 so huge count values cannot bypass the check via overflow. Series load in rdb.c also requires chunkSizeBytes to be non-zero and a multiple of 8.

Flow tests patch valid DUMP outputs (with CRC repair and RDB length re-encoding) to assert "Bad data format" for size/length mismatch, misaligned buffers, and inflated count (including near-UINT64_MAX bypass cases).

Reviewed by Cursor Bugbot for commit 1f8968c. Bugbot is set up for automated code reviews on this repo. 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 e9b8ba9 into 8.2 Sep 14, 2026
55 of 58 checks passed
@AvivDavid23
AvivDavid23 deleted the cherry-pick-b54cdcef-to-8.2 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