This is an automated email from the ASF dual-hosted git repository.

garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git


The following commit(s) were added to refs/heads/master by this push:
     new 8fb590876 Fix abbreviation overflow for extreme negative offsets 
(#1875)
8fb590876 is described below

commit 8fb5908762d48add7c2666dab9daffd1a63a6f97
Author: Amar Ghugare <[email protected]>
AuthorDate: Sun Nov 15 20:56:29 2026 +0530

    Fix abbreviation overflow for extreme negative offsets (#1875)
---
 src/main/java/org/apache/commons/lang3/StringUtils.java  |  2 +-
 .../apache/commons/lang3/StringUtilsAbbreviateTest.java  | 16 ++++++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java 
b/src/main/java/org/apache/commons/lang3/StringUtils.java
index ca181ac87..dba9e8256 100644
--- a/src/main/java/org/apache/commons/lang3/StringUtils.java
+++ b/src/main/java/org/apache/commons/lang3/StringUtils.java
@@ -385,7 +385,7 @@ public static String abbreviate(final String str, String 
abbrevMarker, final int
         if (strLen <= maxWidth) {
             return str;
         }
-        if (strLen - offset <= maxWidth - abbrevMarkerLength) {
+        if ((long) strLen - offset <= maxWidth - abbrevMarkerLength) {
             int tailStart = strLen - (maxWidth - abbrevMarkerLength);
             if (splitsSurrogatePair(str, tailStart)) {
                 tailStart++;
diff --git 
a/src/test/java/org/apache/commons/lang3/StringUtilsAbbreviateTest.java 
b/src/test/java/org/apache/commons/lang3/StringUtilsAbbreviateTest.java
index 9b37cc808..c9a73d257 100644
--- a/src/test/java/org/apache/commons/lang3/StringUtilsAbbreviateTest.java
+++ b/src/test/java/org/apache/commons/lang3/StringUtilsAbbreviateTest.java
@@ -25,6 +25,8 @@
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
 
 /**
  * Tests {@link StringUtils#abbreviate(String, int)} and friends.
@@ -172,6 +174,20 @@ void testAbbreviate_StringStringIntInt() {
         assertEquals("....fg", StringUtils.abbreviate("abcdefg", "....", 5, 
6));
     }
 
+    @ParameterizedTest
+    @ValueSource(ints = { Integer.MIN_VALUE, Integer.MIN_VALUE + 1, 
Integer.MIN_VALUE + 15, Integer.MIN_VALUE + 16, -1, 0 })
+    void testAbbreviateNonPositiveOffset(final int offset) {
+        assertAbbreviateWithOffset("abcdefg...", offset, 10);
+    }
+
+    @ParameterizedTest
+    @ValueSource(ints = { Integer.MIN_VALUE, Integer.MIN_VALUE + 1, 
Integer.MIN_VALUE + 15, Integer.MIN_VALUE + 16, -1, 0 })
+    void testAbbreviateNonPositiveOffsetWithMarker(final int offset) {
+        assertAbbreviateWithAbbrevMarkerAndOffset("abcdefgh++", "++", offset, 
10);
+        assertAbbreviateWithAbbrevMarkerAndOffset("abcdefghij", "", offset, 
10);
+        assertAbbreviateWithAbbrevMarkerAndOffset("abcdefghij", null, offset, 
10);
+    }
+
     // Fixed LANG-1463
     @Test
     void testAbbreviateMarkerWithEmptyString() {

Reply via email to