Skip to content

Prevent narrowing committed counts in indexed end tokens #810

Description

@coderabbitai

Summary

index_router converts a committed count from std::size_t to int when it sends an indexed_end_token. Counts greater than INT_MAX can narrow to an implementation-defined value. A negative value can then cause incorrect subtraction in flush-token handling.

Required changes

  • Change indexed_end_token::count and the corresponding flush-token handling to use std::ptrdiff_t.
  • Update repeater_node::handle_flush_token and related code to preserve the widened count type.
  • Remove the static_cast<int>(count) conversion in the index_router::route flush callback.
  • Preserve the existing count propagation behavior.

Rationale

A fold partition can accumulate more than INT_MAX cells. The current narrowing conversion can silently corrupt the committed count before repeater_node::handle_flush_token processes it.

Affected areas

  • phlex/core/index_router.cpp
  • The indexed_end_token declaration and its producers/consumers
  • repeater_node::handle_flush_token

Acceptance criteria

  • No committed count is narrowed from std::size_t to int during end-token creation.
  • indexed_end_token and all flush-token consumers use std::ptrdiff_t consistently.
  • Existing flush-token count propagation semantics remain unchanged.
  • Add or update tests for counts above INT_MAX, where practical.

Backlinks

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions