You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2018/05/19 13:08:10 UTC
[maven-surefire] branch master updated: [SUREFIRE-1522] fix
escapeBytesToPrintable bounds check
This is an automated email from the ASF dual-hosted git repository.
tibordigana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
The following commit(s) were added to refs/heads/master by this push:
new a8dfec2 [SUREFIRE-1522] fix escapeBytesToPrintable bounds check
a8dfec2 is described below
commit a8dfec2fcf3f1ca14658883d8ba72524f48b35a8
Author: Rob Platt <95...@users.noreply.github.com>
AuthorDate: Thu May 17 18:54:33 2018 +0100
[SUREFIRE-1522] fix escapeBytesToPrintable bounds check
---
.../maven/surefire/util/internal/StringUtils.java | 6 +++---
.../surefire/util/internal/StringUtilsTest.java | 20 ++++++++++++++++++++
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/StringUtils.java b/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/StringUtils.java
index b0665bd..2a0783e 100644
--- a/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/StringUtils.java
+++ b/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/StringUtils.java
@@ -233,7 +233,7 @@ public final class StringUtils
* @return number of bytes written to {@code out}
* @throws NullPointerException if the specified parameter {@code header} or {@code input} is null
* @throws IndexOutOfBoundsException if {@code off} or {@code len} is out of range
- * ({@code off < 0 || len < 0 || off >= input.length || len > input.length || off > len})
+ * ({@code off < 0 || len < 0 || off >= input.length || len > input.length || off + len > input.length})
*/
@SuppressWarnings( "checkstyle:magicnumber" )
public static EncodedArray escapeBytesToPrintable( final byte[] header, final byte[] input, final int off,
@@ -243,10 +243,10 @@ public final class StringUtils
{
return EncodedArray.EMPTY;
}
- if ( off < 0 || len < 0 || off >= input.length || len > input.length || off > len )
+ if ( off < 0 || len < 0 || off >= input.length || len > input.length || off + len > input.length )
{
throw new IndexOutOfBoundsException(
- "off < 0 || len < 0 || off >= input.length || len > input.length || off > len" );
+ "off < 0 || len < 0 || off >= input.length || len > input.length || off + len > input.length" );
}
// Hex-escaping can be up to 3 times length of a regular byte. Last character is '\n', see (+1).
final byte[] encodeBytes = new byte[header.length + 3 * len + 1];
diff --git a/surefire-api/src/test/java/org/apache/maven/surefire/util/internal/StringUtilsTest.java b/surefire-api/src/test/java/org/apache/maven/surefire/util/internal/StringUtilsTest.java
index 96e5ed3..e686086 100644
--- a/surefire-api/src/test/java/org/apache/maven/surefire/util/internal/StringUtilsTest.java
+++ b/surefire-api/src/test/java/org/apache/maven/surefire/util/internal/StringUtilsTest.java
@@ -119,4 +119,24 @@ public class StringUtilsTest
assertEquals( 0, encodedArray.getSize() );
assertEquals( 0, encodedArray.getArray().length );
}
+
+ public void testSubstringSmall()
+ {
+ byte[] header = { (byte) 'a' };
+ byte[] input = "PleaseLookAfterThisBear".getBytes();
+ EncodedArray encodedArray = StringUtils.escapeBytesToPrintable( header, input,
+ "Please".length(), "Look".length() );
+ assertEquals( "Look",
+ new String( encodedArray.getArray(), 1, encodedArray.getArray().length-1).trim() );
+ }
+
+ public void testSubstringLarge()
+ {
+ byte[] header = { (byte) 'a' };
+ byte[] input = "TheQuickBrownFoxJumpsOverTheLazyDog".getBytes();
+ EncodedArray encodedArray = StringUtils.escapeBytesToPrintable( header, input,
+ "The".length(), "QuickBrownFoxJumpsOverTheLazy".length() );
+ assertEquals( "QuickBrownFoxJumpsOverTheLazy",
+ new String( encodedArray.getArray(), 1, encodedArray.getArray().length-1).trim() );
+ }
}
--
To stop receiving notification emails like this one, please contact
tibordigana@apache.org.