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

Laurent Goujon commented on HADOOP-12677:
-----------------------------------------

The unit test is incorrect. According to 
http://docs.oracle.com/javase/7/docs/api/java/io/InputStream.html#skip%28long%29,
 it doesn't throw EOFException and should return how many bytes were skipped. 
So the catch clause should be removed, and instead the return value should be 
checked (it should be 4). It looks also that the following check 
{code:java} if (bufLen > 0){code}
is not needed since you set bufLen to 4 just before.

Regarding the fix, it looks correct. Style-wise, some parenthesis and casts are 
probably not needed, and I believe it could be on a single line:
{code:java}
// safe to cast to int as between between 0 and skipBytes.length
int len = (int) Math.min(n - skipped, skipBytes.length);
{code}

> DecompressorStream throws IndexOutOfBoundsException when calling skip(long)
> ---------------------------------------------------------------------------
>
>                 Key: HADOOP-12677
>                 URL: https://issues.apache.org/jira/browse/HADOOP-12677
>             Project: Hadoop Common
>          Issue Type: Bug
>          Components: io
>    Affects Versions: 2.4.0, 2.6.0, 3.0.0
>            Reporter: Laurent Goujon
>            Assignee: Wei-Chiu Chuang
>         Attachments: HADOOP-12677.001.patch
>
>
> DecompressorStream.skip(long) throws an IndexOutOfBoundException when using a 
> long bigger than Integer.MAX_VALUE
> This is because of this cast from long to int: 
> https://github.com/apache/hadoop-common/blob/HADOOP-3628/src/core/org/apache/hadoop/io/compress/DecompressorStream.java#L125
> The fix is probably to do the cast after applying Math.min: in that case, it 
> should not be an issue since it should not be bigger than the buffer size 
> (512)



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to