Skip to content

fix(ethexe/malachite): saturate Fin sequence to avoid overflow in StreamState#5500

Draft
grishasobol wants to merge 2 commits into
masterfrom
gsobol/ethexe/fix-streaming-fin-overflow
Draft

fix(ethexe/malachite): saturate Fin sequence to avoid overflow in StreamState#5500
grishasobol wants to merge 2 commits into
masterfrom
gsobol/ethexe/fix-streaming-fin-overflow

Conversation

@grishasobol

@grishasobol grishasobol commented May 22, 2026

Copy link
Copy Markdown
Member

No description provided.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical vulnerability where a maliciously crafted or extreme sequence value in a Fin message could cause the engine to panic in debug mode or enter an inconsistent state in release mode. By switching to saturating arithmetic, the system now gracefully handles these edge cases, ensuring stability in the stream processing logic.

Highlights

  • Arithmetic Overflow Fix: Updated the sequence calculation in StreamState to use saturating_add(1) instead of a standard addition, preventing potential panics or integer wrapping when a peer sends a sequence value of u64::MAX.
  • Regression Testing: Added a new test case, fin_at_u64_max_sequence_does_not_panic, to ensure that receiving a Fin message with the maximum possible sequence value does not crash the engine.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request addresses a potential panic and overflow vulnerability in the streaming module by replacing unchecked addition with saturating addition when calculating total messages from a peer-controlled sequence number. A regression test has been added to ensure that a sequence number of u64::MAX does not cause a crash. The review feedback correctly identifies that the 'as usize' cast remains a risk on 32-bit platforms where truncation could occur, and suggests using a safer try_into conversion with context as per repository standards.

Comment thread ethexe/malachite/core/src/streaming.rs
@grishasobol grishasobol self-assigned this May 22, 2026
@grishasobol grishasobol marked this pull request as draft May 22, 2026 11:28
Base automatically changed from gsobol/ethexe/malachite-new to master May 25, 2026 16:59
@grishasobol grishasobol force-pushed the gsobol/ethexe/fix-streaming-fin-overflow branch from d656f44 to 7ced688 Compare May 25, 2026 17:13
@grishasobol grishasobol marked this pull request as ready for review May 25, 2026 18:48

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request prevents panics or silent wrapping of total_messages in StreamState when receiving a peer-controlled Fin message with a sequence number of u64::MAX by replacing the unchecked addition with saturating_add(1). It also adds a regression test for this scenario. The reviewer suggested using try_into() instead of a direct as usize cast to prevent silent truncation on 32-bit targets.

Comment thread ethexe/malachite/core/src/streaming.rs
@grishasobol grishasobol marked this pull request as draft June 8, 2026 07:23
grishasobol and others added 2 commits June 8, 2026 09:39
…eamState

A peer-controlled `Fin` with `sequence == u64::MAX` triggered an
overflow panic at `streaming.rs:101` under the workspace dev profile
(overflow-checks=on) — crashing the engine's app task on a single
wire-legal stream message. In release the same input silently wrapped
`total_messages` to 0, leaving the slot stuck forever.

Switch to `saturating_add` so neither failure mode is possible.
Leftover stuck-slot behaviour (counters complete but no Init) is
covered by the broader PartStreamsMap caps + GC tracked as #5473.

Regression test added.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Removed comments and a test related to handling peer-controlled Fin messages with sequence number at u64::MAX.
@grishasobol grishasobol force-pushed the gsobol/ethexe/fix-streaming-fin-overflow branch from 0ffc97b to 1d7b29a Compare June 8, 2026 07:42
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.

1 participant