You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2020/01/02 08:36:00 UTC

[jira] [Updated] (HDDS-2784) Read to ByteBuffer uses wrong offset

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

ASF GitHub Bot updated HDDS-2784:
---------------------------------
    Labels: pull-request-available  (was: )

> Read to ByteBuffer uses wrong offset
> ------------------------------------
>
>                 Key: HDDS-2784
>                 URL: https://issues.apache.org/jira/browse/HDDS-2784
>             Project: Hadoop Distributed Data Store
>          Issue Type: Bug
>          Components: Ozone Filesystem
>            Reporter: Attila Doroszlai
>            Assignee: Attila Doroszlai
>            Priority: Major
>              Labels: pull-request-available
>
> {{OzoneFSInputStream#read(ByteBuffer)}} uses the target buffer's position for offsetting into the temporary array:
> {code:title=https://github.com/apache/hadoop-ozone/blob/b834fa48afef4ee4c73577c7af564e1e97cb9d5b/hadoop-ozone/ozonefs/src/main/java/org/apache/hadoop/fs/ozone/OzoneFSInputStream.java#L90-L97}
>   public int read(ByteBuffer buf) throws IOException {
>     int bufInitPos = buf.position();
>     int readLen = Math.min(buf.remaining(), inputStream.available());
>     byte[] readData = new byte[readLen];
>     int bytesRead = inputStream.read(readData, bufInitPos, readLen);
>     buf.put(readData);
> {code}
> Given a buffer with capacity=10 and position=8, this results in the following:
>  * {{readLen}} = 2 => {{readData.length}} = 2
>  * {{bufInitPos}} = 8
> So {{inputStream}} reads 2 bytes and writes it into {{readData}} starting at offset 8, which results in an {{IndexOutOfBoundsException}}.
> offset should always be 0, since the temporary array is sized exactly for the length to read, and it has no extra data at the start.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: ozone-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: ozone-issues-help@hadoop.apache.org