GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [fix][client] Reject relative times whose conversion to seconds overflows by hechen0 · Pull Request #27464 · apache/pulsar

Conversation

@hechen0

@hechen0 hechen0 commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Fixes #27377

Motivation

RelativeTimeUtil.parseRelativeTimeInSeconds silently fabricates a result for durations whose unit conversion overflows a signed 64-bit seconds count, while every other malformed input (empty string, non-numeric value, invalid unit) is rejected with IllegalArgumentException:

  • TimeUnit.toSeconds saturates at Long.MAX_VALUE instead of failing, so 9223372036854775807m parses as 9223372036854775807 seconds — a value that looks legitimate.
  • the w and y cases then multiply the saturated value with a plain long multiplication that wraps around, so 15252526452552645w parses as 9223372036854775801 seconds.

These strings come from user-supplied relative times in CLI options (the pulsar-admin commands and TokensCliUtils behind TimeUnitToSecondsConverter / TimeUnitToMillisConverter), where an extra digit currently passes validation and yields a silently wrong TTL/retention-style policy instead of a loud error.

Modifications

  • Convert the duration to seconds with Math.multiplyExact for every unit and rethrow the ArithmeticException as an IllegalArgumentException carrying the offending input, aligning overflow with the parser's existing failure modes.
  • Apply the same fix to the copy of RelativeTimeUtil in pulsar-cli-utils.

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests and can be verified as follows:

  • Extended RelativeTimeUtilTest with the largest non-overflowing duration of each unit and the first duration past it, the two examples from the issue, a negative overflow, and the Long.MAX_VALUE seconds boundary.

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Relative-time option values whose conversion to seconds overflows now fail fast with IllegalArgumentException instead of being accepted with a silently wrong value. Correctly sized values parse exactly as before.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@hechen0
[fix][common] Reject relative times whose conversion to seconds overf…
eb2c7a3
…lows

RelativeTimeUtil.parseRelativeTimeInSeconds silently fabricated a result
for durations whose unit conversion overflows a signed 64-bit seconds
count: the TimeUnit conversions saturated for m/h/d, and the raw
multiplications for w/y wrapped around. Every other malformed input is
already rejected loudly, so reject these too, throwing
IllegalArgumentException from Math.multiplyExact instead.

Apply the same fix to the copy of RelativeTimeUtil in pulsar-cli-utils.

Fixes apache#27377
Assisted-by: ZCode
codelipenghui
codelipenghui approved these changes Nov 8, 2026
View reviewed changes
@hechen0 hechen0 changed the title [fix][common] Reject relative times whose conversion to seconds overflows [fix][client] Reject relative times whose conversion to seconds overflows Nov 9, 2026
@codelipenghui
codelipenghui merged commit 6b276a8 into apache:master Nov 9, 2026
43 of 44 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@hechen0
hechen0 deleted the fix-27377-relative-time-overflow branch November 9, 2026 05:21
lhotari pushed a commit that referenced this pull request Nov 9, 2026
@hechen0 @lhotari
[fix][client] Reject relative times whose conversion to seconds overf…
5e25082
…lows (#27464)

(cherry picked from commit 6b276a8)
@lhotari lhotari added release/5.0.2 cherry-picked/branch-5.0 labels Nov 9, 2026
@AP24110011695 AP24110011695 mentioned this pull request Nov 9, 2026
[Bug][common] RelativeTimeUtil.parseRelativeTimeInSeconds silently fabricates a value instead of rejecting overflow-sized relative times #27377
Closed
1 task done
This was referenced Nov 21, 2026
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27680
Closed
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27681
Closed
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27684
Closed
@lhotari lhotari added cherry-picked/branch-4.2 release/4.2.6 cherry-picked/branch-4.0 release/4.0.15 labels Nov 21, 2026
ascentstream-bot pushed a commit to ascentstream/pulsar that referenced this pull request Nov 24, 2026
@hechen0 @lhotari
[fix][client] Reject relative times whose conversion to seconds overf…
29b7f31
…lows (apache#27464)

(cherry picked from commit 6b276a8)
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@hechen0 @lhotari
[fix][client] Reject relative times whose conversion to seconds overf…
5352a6f
…lows (apache#27464)

(cherry picked from commit 6b276a8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@codelipenghui codelipenghui codelipenghui approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

cherry-picked/branch-4.0 cherry-picked/branch-4.2 cherry-picked/branch-5.0 release/4.0.15 release/4.2.6 release/5.0.2

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[Bug][common] RelativeTimeUtil.parseRelativeTimeInSeconds silently fabricates a value instead of rejecting overflow-sized relative times

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@hechen0 @codelipenghui @lhotari
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.