hadoop-common-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dapeng Sun (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (HADOOP-12869) CryptoInputStream#read() may return incorrect result
Date Thu, 03 Mar 2016 03:31:18 GMT

     [ https://issues.apache.org/jira/browse/HADOOP-12869?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Dapeng Sun updated HADOOP-12869:
--------------------------------
    Description: 
Here is the comment of InputStream#read():
{noformat} 
   /**
     * Reads the next byte of data from the input stream. The value byte is
     * returned as an <code>int</code> in the range <code>0</code>
to
     * <code>255</code>. If no byte is available because the end of the stream
     * has been reached, the value <code>-1</code> is returned. This method
     * blocks until input data is available, the end of the stream is detected,
     * or an exception is thrown.
     *
     * <p> A subclass must provide an implementation of this method.
     *
     * @return     the next byte of data, or <code>-1</code> if the end of the
     *             stream is reached.
     * @exception  IOException  if an I/O error occurs.
     */
    public abstract int read() throws IOException;
{noformat} 
Here is the implemention of {{CryptoInputStream#read()}} in Hadoop Common:
{noformat}
@Override
public int read() throws IOException {
  return (read(oneByteBuf, 0, 1) == -1) ? -1 : (oneByteBuf[0] & 0xff);		
}
{noformat}
The return value of {{read(oneByteBuf, 0, 1)}} maybe 1, -1 and 0:
For {{1}}: we should return the content of {{oneByteBuf}}
For {{-1}}: we should return {{-1}} to stand for the end of stream
For {{0}}: it means we didn't get decryption data back and it is not the end of the stream,
we should continue to decrypt the stream.


> CryptoInputStream#read() may return incorrect result
> ----------------------------------------------------
>
>                 Key: HADOOP-12869
>                 URL: https://issues.apache.org/jira/browse/HADOOP-12869
>             Project: Hadoop Common
>          Issue Type: Bug
>          Components: security
>    Affects Versions: 2.7.2, 3.0.0
>            Reporter: Dapeng Sun
>            Assignee: Dapeng Sun
>         Attachments: HADOOP-12869.001.patch
>
>
> Here is the comment of InputStream#read():
> {noformat} 
>    /**
>      * Reads the next byte of data from the input stream. The value byte is
>      * returned as an <code>int</code> in the range <code>0</code>
to
>      * <code>255</code>. If no byte is available because the end of the stream
>      * has been reached, the value <code>-1</code> is returned. This method
>      * blocks until input data is available, the end of the stream is detected,
>      * or an exception is thrown.
>      *
>      * <p> A subclass must provide an implementation of this method.
>      *
>      * @return     the next byte of data, or <code>-1</code> if the end of
the
>      *             stream is reached.
>      * @exception  IOException  if an I/O error occurs.
>      */
>     public abstract int read() throws IOException;
> {noformat} 
> Here is the implemention of {{CryptoInputStream#read()}} in Hadoop Common:
> {noformat}
> @Override
> public int read() throws IOException {
>   return (read(oneByteBuf, 0, 1) == -1) ? -1 : (oneByteBuf[0] & 0xff);		
> }
> {noformat}
> The return value of {{read(oneByteBuf, 0, 1)}} maybe 1, -1 and 0:
> For {{1}}: we should return the content of {{oneByteBuf}}
> For {{-1}}: we should return {{-1}} to stand for the end of stream
> For {{0}}: it means we didn't get decryption data back and it is not the end of the stream,
we should continue to decrypt the stream.



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

Mime
View raw message