Skip to content

fix: Integer overflow in range filter boundary conversion (#27600)#27600

Open
peterenescu wants to merge 1 commit intoprestodb:masterfrom
peterenescu:export-D101072577
Open

fix: Integer overflow in range filter boundary conversion (#27600)#27600
peterenescu wants to merge 1 commit intoprestodb:masterfrom
peterenescu:export-D101072577

Conversation

@peterenescu
Copy link
Copy Markdown

@peterenescu peterenescu commented Apr 16, 2026

Summary:

Guard against integer overflow when converting exclusive bounds to inclusive bounds for BigintRange, HugeintRange, and TimestampRange filters in the OSS Hive connector. When the boundary value is at the type limit, return AlwaysFalse or IsNull instead of overflowing. This mirrors the fix applied to the Prism connector and Velox expression filters.

NO RELEASE NOTE

Differential Revision: D101072577

@peterenescu peterenescu requested review from a team as code owners April 16, 2026 16:24
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla bot commented Apr 16, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: peterenescu / name: Peter Enescu (66d2dab)

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Apr 16, 2026

Reviewer's Guide

Adds overflow-safe conversion from protocol Range to Velox filters for bigint, hugeint, and timestamp in the OSS Hive connector, returning AlwaysFalse/IsNull instead of overflowing when exclusive bounds sit at type limits, and updates range-combination logic to handle these new filter types correctly.

Class diagram for Filter hierarchy and updated range conversion helpers

classDiagram
  class Filter {
    <<interface>>
    +FilterKind kind()
  }

  class FilterKind {
    <<enumeration>>
    kAlwaysFalse
    kIsNull
    kBigintRange
    kHugeintRange
    kTimestampRange
  }

  class BigintRange {
    +int64_t low
    +int64_t high
    +bool nullAllowed
    +FilterKind kind()
  }

  class HugeintRange {
    +int128_t low
    +int128_t high
    +bool nullAllowed
    +FilterKind kind()
  }

  class TimestampRange {
    +Timestamp low
    +Timestamp high
    +bool nullAllowed
    +FilterKind kind()
  }

  class AlwaysFalse {
    +FilterKind kind()
  }

  class IsNull {
    +FilterKind kind()
  }

  class PrestoToVeloxConnectorUtils {
    +bigintRangeToFilter(Range range, bool nullAllowed, VeloxExprConverter exprConverter, TypePtr type) Filter*
    +hugeintRangeToFilter(Range range, bool nullAllowed, VeloxExprConverter exprConverter, TypePtr type) Filter*
    +timestampRangeToFilter(Range range, bool nullAllowed, VeloxExprConverter exprConverter, TypePtr type) Filter*
    +toFilter(RangeList ranges, bool nullAllowed, VeloxExprConverter exprConverter, TypePtr type) Filter*
  }

  Filter <|-- BigintRange
  Filter <|-- HugeintRange
  Filter <|-- TimestampRange
  Filter <|-- AlwaysFalse
  Filter <|-- IsNull

  FilterKind <.. Filter
  PrestoToVeloxConnectorUtils ..> Filter
  PrestoToVeloxConnectorUtils ..> BigintRange
  PrestoToVeloxConnectorUtils ..> HugeintRange
  PrestoToVeloxConnectorUtils ..> TimestampRange
  PrestoToVeloxConnectorUtils ..> AlwaysFalse
  PrestoToVeloxConnectorUtils ..> IsNull
Loading

Flow diagram for overflow-safe bigintRangeToFilter conversion

flowchart TD
  A[Start bigintRangeToFilter] --> B[Compute lowUnbounded and highUnbounded]
  B --> C[low = lowUnbounded ? int64_min : toInt64]
  C --> D{!lowUnbounded and lowBound is ABOVE?}
  D --> E[Check highUnbounded and compute high]:::hidden
  D --> F{low == int64_max?}
  classDef hidden stroke-width:0,fill-opacity:0,color:transparent
  D -- No --> E
  F --> G{nullAllowed?}
  F -- No --> H[low++]
  G --> I[Return IsNull filter]
  G --> J[Return AlwaysFalse filter]
  H --> E
  E --> K{!highUnbounded and highBound is BELOW?}
  K --> L["Return BigintRange(low, high, nullAllowed)"]
  K --> M{high == int64_min?}
  M --> N{nullAllowed?}
  M -- No --> O[high--]
  N --> P[Return IsNull filter]
  N --> Q[Return AlwaysFalse filter]
  O --> L

  style A stroke:#333,stroke-width:1px
  style L stroke:#333,stroke-width:1px
  style I stroke:#333,stroke-width:1px
  style J stroke:#333,stroke-width:1px
  style P stroke:#333,stroke-width:1px
  style Q stroke:#333,stroke-width:1px
Loading

File-Level Changes

Change Details Files
Generalize bigint/hugeint/timestamp range conversion helpers to return generic Filter and guard exclusive-bound increment/decrement at type limits by yielding AlwaysFalse or IsNull instead of overflowing.
  • Change return type of bigintRangeToFilter, hugeintRangeToFilter, and timestampRangeToFilter from concrete Range types to std::unique_ptrcommon::Filter.
  • Before incrementing low for ABOVE bounds, check if low is at the max value for the underlying type and return IsNull or AlwaysFalse accordingly.
  • Before decrementing high for BELOW bounds, check if high is at the min value for the underlying type and return IsNull or AlwaysFalse accordingly.
  • Keep existing construction of BigintRange, HugeintRange, and TimestampRange when safe (no overflow risk).
presto-native-execution/presto_cpp/main/connectors/PrestoToVeloxConnectorUtils.cpp
Update bigint toFilter path to consume the generalized filter helpers and correctly handle AlwaysFalse/IsNull results when combining multiple ranges.
  • Call bigintRangeToFilter to build a Filter per range and skip ranges that produce AlwaysFalse or IsNull when populating bigintFilters.
  • If all ranges produce AlwaysFalse/IsNull, return a top-level IsNull or AlwaysFalse based on nullAllowed.
  • If only one non-trivial bigint range remains, return it directly instead of calling combineIntegerRanges.
  • Retain existing behavior of combining multiple integer ranges via combineIntegerRanges when there are at least two ranges.
presto-native-execution/presto_cpp/main/connectors/PrestoToVeloxConnectorUtils.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Now that bigintRangeToFilter/hugeintRangeToFilter/timestampRangeToFilter return common::Filter, make sure all their call sites are updated to handle possible AlwaysFalse/IsNull results consistently, not just the bigint ranges case in toFilter.
  • The overflow handling for bigint, hugeint, and timestamp ranges is duplicated; consider extracting a small helper (e.g., a template or lambda taking min/max and nullAllowed) to centralize the guard and avoid future divergence between these three paths.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Now that bigintRangeToFilter/hugeintRangeToFilter/timestampRangeToFilter return common::Filter, make sure all their call sites are updated to handle possible AlwaysFalse/IsNull results consistently, not just the bigint ranges case in toFilter.
- The overflow handling for bigint, hugeint, and timestamp ranges is duplicated; consider extracting a small helper (e.g., a template or lambda taking min/max and nullAllowed) to centralize the guard and avoid future divergence between these three paths.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@steveburnett
Copy link
Copy Markdown
Contributor

  • Please sign the Presto CLA.

  • Please add a release note - or NO RELEASE NOTE - following the Release Notes Guidelines to pass the failing but not required CI check.

@meta-codesync meta-codesync bot changed the title fix: Integer overflow in range filter boundary conversion fix: Integer overflow in range filter boundary conversion (#27600) Apr 16, 2026
peterenescu added a commit to peterenescu/presto that referenced this pull request Apr 16, 2026
…7600)

Summary:

Guard against integer overflow when converting exclusive bounds to inclusive bounds for BigintRange, HugeintRange, and TimestampRange filters in the OSS Hive connector. When the boundary value is at the type limit, return AlwaysFalse or IsNull instead of overflowing. This mirrors the fix applied to the Prism connector and Velox expression filters.

Differential Revision: D101072577
@meta-codesync meta-codesync bot changed the title fix: Integer overflow in range filter boundary conversion (#27600) fix: Integer overflow in range filter boundary conversion Apr 16, 2026
@meta-codesync meta-codesync bot changed the title fix: Integer overflow in range filter boundary conversion fix: Integer overflow in range filter boundary conversion (#27600) Apr 16, 2026
peterenescu added a commit to peterenescu/presto that referenced this pull request Apr 16, 2026
…7600)

Summary:

Guard against integer overflow when converting exclusive bounds to inclusive bounds for BigintRange, HugeintRange, and TimestampRange filters in the OSS Hive connector. When the boundary value is at the type limit, return AlwaysFalse or IsNull instead of overflowing. This mirrors the fix applied to the Prism connector and Velox expression filters.
```
NO RELEASE NOTE
```

Differential Revision: D101072577
peterenescu added a commit to peterenescu/presto that referenced this pull request Apr 16, 2026
…7600)

Summary:

Guard against integer overflow when converting exclusive bounds to inclusive bounds for BigintRange, HugeintRange, and TimestampRange filters in the OSS Hive connector. When the boundary value is at the type limit, return AlwaysFalse or IsNull instead of overflowing. This mirrors the fix applied to the Prism connector and Velox expression filters.
```
NO RELEASE NOTE
```

Differential Revision: D101072577
…7600)

Summary:
Pull Request resolved: prestodb#27600

Guard against integer overflow when converting exclusive bounds to inclusive bounds for BigintRange, HugeintRange, and TimestampRange filters in the OSS Hive connector. When the boundary value is at the type limit, return AlwaysFalse or IsNull instead of overflowing. This mirrors the fix applied to the Prism connector and Velox expression filters.
```
NO RELEASE NOTE
```

Differential Revision: D101072577
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.

2 participants