G
YouTube TikTok Games
Skip to content

Fix abbreviation overflow for extreme negative offsets - #1875

Open
AmarGhugare wants to merge 1 commit into
apache:masterfrom
AmarGhugare:fix/abbreviate-offset-overflow
Open

AmarGhugare wants to merge 1 commit into
apache:masterfrom
AmarGhugare:fix/abbreviate-offset-overflow

Conversation

@AmarGhugare

Copy link
Copy Markdown
Contributor

StringUtils.abbreviate("abcdefghijklmno", Integer.MIN_VALUE, 10) returns ...ijklmno instead of abcdefg.... Negative offsets already select the beginning in the documented examples, but the length-minus-offset subtraction overflows for sufficiently negative values and incorrectly selects the tail branch.

Perform that subtraction in long arithmetic. The existing comparison and abbreviation behavior are preserved without adding an API. Regression tests cover both offset overloads, values on either side of the overflow boundary, ordinary negative/zero offsets, and custom/empty/null markers. Six cases fail without the fix.

Validation: mvn -o -B -ntp passed on JDK 25.0.4.1: 119,340 tests run, zero failures/errors, and 18 skipped. Coverage, license checks, Checkstyle, binary compatibility, SpotBugs, PMD, and Javadoc checks passed.

Jira filing is pending approval of the Apache Jira account. The reproduction and proposed fix are included here for review in the meantime.

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