[ 
https://issues.apache.org/jira/browse/SUREFIRE-1522?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16480835#comment-16480835
 ] 

ASF GitHub Bot commented on SUREFIRE-1522:
------------------------------------------

docrjp commented on issue #185: [SUREFIRE-1522] fix escapeBytesToPrintable 
bounds check
URL: https://github.com/apache/maven-surefire/pull/185#issuecomment-390253454
 
 
   @Tibor17 now passes on a mvn install:
   
   Results :
   
   Tests run: 756, Failures: 0, Errors: 0, Skipped: 138
   
   [INFO]
   [INFO] --- maven-checkstyle-plugin:2.15:check (checkstyle-check) @ 
surefire-its ---
   [INFO]
   [INFO] --- maven-failsafe-plugin:2.12.4:verify (default) @ surefire-its ---
   [INFO] Failsafe report directory: [redacted]
   [INFO]
   [INFO] --- maven-install-plugin:2.5.2:install (default-install) @ 
surefire-its ---
   [INFO] Skipping artifact installation
   [INFO] 
------------------------------------------------------------------------
   [INFO] Reactor Summary:
   [INFO]
   [INFO] Apache Maven Surefire .............................. SUCCESS [  5.148 
s]
   [INFO] SureFire Logger API ................................ SUCCESS [  2.049 
s]
   [INFO] SureFire API ....................................... SUCCESS [  7.176 
s]
   [INFO] ShadeFire JUnit3 Provider .......................... SUCCESS [  2.075 
s]
   [INFO] SureFire Booter .................................... SUCCESS [ 13.905 
s]
   [INFO] Maven Surefire Test-Grouping Support ............... SUCCESS [  4.905 
s]
   [INFO] SureFire Providers ................................. SUCCESS [  0.671 
s]
   [INFO] Shared JUnit3 Provider Code ........................ SUCCESS [  4.368 
s]
   [INFO] Shared Java 5 Provider Base ........................ SUCCESS [  4.546 
s]
   [INFO] Shared JUnit4 Provider Code ........................ SUCCESS [  4.797 
s]
   [INFO] Shared JUnit48 Provider Code ....................... SUCCESS [  5.353 
s]
   [INFO] SureFire JUnit Runner .............................. SUCCESS [  4.266 
s]
   [INFO] SureFire JUnit4 Runner ............................. SUCCESS [  5.803 
s]
   [INFO] Maven Surefire Common .............................. SUCCESS [ 28.821 
s]
   [INFO] SureFire JUnitCore Runner .......................... SUCCESS [02:12 
min]
   [INFO] SureFire TestNG Utils .............................. SUCCESS [  3.989 
s]
   [INFO] SureFire TestNG Runner ............................. SUCCESS [  4.324 
s]
   [INFO] Surefire Report Parser ............................. SUCCESS [  4.411 
s]
   [INFO] Maven Surefire Plugin .............................. SUCCESS [  8.950 
s]
   [INFO] Maven Failsafe Plugin .............................. SUCCESS [ 11.370 
s]
   [INFO] Maven Surefire Report Plugin ....................... SUCCESS [ 13.593 
s]
   [INFO] Maven Surefire Integration Test Setup .............. SUCCESS [ 35.182 
s]
   [INFO] Maven Surefire Integration Tests ................... SUCCESS [  01:04 
h]
   [INFO] 
------------------------------------------------------------------------
   [INFO] BUILD SUCCESS
   [INFO] 
------------------------------------------------------------------------
   [INFO] Total time: 01:09 h
   [INFO] Finished at: 2018-05-18T15:01:40+01:00
   [INFO] Final Memory: 52M/663M
   [INFO] 
------------------------------------------------------------------------
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> IndexOutOfBoundsException for System.out.write
> ----------------------------------------------
>
>                 Key: SUREFIRE-1522
>                 URL: https://issues.apache.org/jira/browse/SUREFIRE-1522
>             Project: Maven Surefire
>          Issue Type: Bug
>          Components: Maven Failsafe Plugin, Maven Surefire Plugin, process 
> forking
>    Affects Versions: 2.21.0
>            Reporter: Rob Platt
>            Assignee: Tibor Digana
>            Priority: Major
>             Fix For: 2.22.0
>
>
> There is a regression, I believe caused by -SUREFIRE-1454-. Git blame seems 
> to confirm this; and there was a related regression for empty arrays 
> SUREFIRE-1515.
> It can be easily reproduced with the following test:
>  
> {code:java}
> import org.junit.jupiter.api.Test;
> import java.nio.charset.StandardCharsets;
> public class SurefireLoggingTest {
>     private final byte[] aNiceString = "what fun times, standard out is 
> broken\n".getBytes(StandardCharsets.US_ASCII);
>     @Test
>     public void fun() {
>         System.out.write(aNiceString, 5, 3);
>     }
>     @Test
>     public void fun_times() {
>         System.out.write(aNiceString, 5, 9);
>     }
> }
> {code}
>  
> Both tests will pass under Intellij, writing "fun" and "fun times" to 
> System.out. Whereas, with Surefire capturing standard out when running from 
> maven, only fun_times() passes. fun() will fail with:
>  
> {noformat}
> java.lang.IndexOutOfBoundsException: off < 0 || len < 0 || off >= 
> input.length || len > input.length || off > len{noformat}
>  
> If you look at the Javadoc contract for PrintStream.write(byte buf[], int 
> off, int len), you can see that len is "Number of bytes to write", so you can 
> see that it should be fine to print the substring "fun", of length 3, at 
> offset 5. And indeed that is what happens in Intellij.
>  
> I suspect that the failing test isolates the problem to when the offset 
> "exceeds" the length of the substring. The wrong length is being checked in 
> StringUtils.escapeBytesToPrintable(). I think that the check intended to 
> ensure the offset didn't exceed the end of the byte array, not the length of 
> the slice. But that is already covered by "off >= input.length". So there is 
> no benefit to also checking "off > len".



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to