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

Chu Cheng Li updated HDDS-16721:
--------------------------------
    Description: 
*Problem*
{{StreamBlockInputStream.read()}} returns the value from 
{{readBuffer.getByteBuffer().get()}}. It does not change this signed byte to an 
unsigned value. Thus:
* A byte from 0x80 to 0xFE gives a negative value.
* The byte 0xFF gives -1. For a caller, -1 means the end of the stream.

{{InputStream.read()}} must return a value from 0 to 255, or -1 at the end of 
the stream.

*Effect*
The problem occurs in the streaming read 
({{ozone.client.stream.readblock.enable}}) when a caller reads one byte at a 
time. {{KeyInputStream}} reads into a {{ByteBuffer}}. Thus, most reads do not 
have this problem.

*Fix*
* Change {{read()}} to return {{Byte.toUnsignedInt(...)}}.
* Add a test that reads the byte 0xFF.

The split of https://github.com/apache/ozone/pull/10743 showed this problem. 
The Ratis read stream in that PR extends {{StreamBlockInputStream}}.

  was:
{{StreamBlockInputStream.read()}} returns the byte it reads sign-extended: it 
returns {{readBuffer.getByteBuffer().get()}} as is. A byte of 0x80 or more 
comes back as a negative number, and 0xFF comes back as -1, which callers take 
as the end of the stream. {{InputStream.read()}} must return 0 to 255, or -1 at 
the end of the stream.

This affects the streaming read ({{ozone.client.stream.readblock.enable}}) for 
callers that read single bytes. {{KeyInputStream}} reads through 
{{ByteBuffer}}s, so most reads do not hit it.

The fix is to return {{Byte.toUnsignedInt(...)}}, with a test that reads 0xFF.


> StreamBlockInputStream.read() returns a negative value for bytes 0x80 to 0xFF
> -----------------------------------------------------------------------------
>
>                 Key: HDDS-16721
>                 URL: https://issues.apache.org/jira/browse/HDDS-16721
>             Project: Apache Ozone
>          Issue Type: Sub-task
>          Components: Ozone Client
>            Reporter: Chu Cheng Li
>            Assignee: Chu Cheng Li
>            Priority: Major
>
> *Problem*
> {{StreamBlockInputStream.read()}} returns the value from 
> {{readBuffer.getByteBuffer().get()}}. It does not change this signed byte to 
> an unsigned value. Thus:
> * A byte from 0x80 to 0xFE gives a negative value.
> * The byte 0xFF gives -1. For a caller, -1 means the end of the stream.
> {{InputStream.read()}} must return a value from 0 to 255, or -1 at the end of 
> the stream.
> *Effect*
> The problem occurs in the streaming read 
> ({{ozone.client.stream.readblock.enable}}) when a caller reads one byte at a 
> time. {{KeyInputStream}} reads into a {{ByteBuffer}}. Thus, most reads do not 
> have this problem.
> *Fix*
> * Change {{read()}} to return {{Byte.toUnsignedInt(...)}}.
> * Add a test that reads the byte 0xFF.
> The split of https://github.com/apache/ozone/pull/10743 showed this problem. 
> The Ratis read stream in that PR extends {{StreamBlockInputStream}}.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to