New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix BufferedInputStream.read() for values bigger than 0x7f #1922
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, other than the formatting issue.
val inputArray = Array[Byte](0x85.toByte) | ||
val arrayIn = new ByteArrayInputStream(inputArray) | ||
val in = new BufferedInputStream(arrayIn) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not correctly formatted according to scalafmt.
`read()` should return a value between `-1` and `255` and `-1` means `EOF`. When `buf(pos)` contains value bigger than `0x7f` for example `171.toByte` and makes `.toInt`, it converts this value to `-85` that can be regarded by enduser as `EOF` if he uses `< 0` condition. Unfortunately this bug hasn't got workaround on user side because when stream contains `0xff`, the `read()` returns `-1` and it is impossibly to distinguish the `EOF` and `0xff`.
dd6b533
to
7bc78b4
Compare
0x7f
via BufferedInputStream
I was hoping that #1918 might be fixed by this but it isn't. Maybe a stream is reading passed the end of a buffer. @LeeTibbert I don't think your fixes would hurt either. |
…ive#1922) `read()` should return a value between `-1` and `255` and `-1` means `EOF`.
…cala-native#1922)" This reverts commit d4bbc6e.
…cala-native#1922)" This reverts commit d4bbc6e.
I was wrong. It is possibly to overstep this issue on The workaround: class ScalaNativeFriendlyBufferedInputStream(in: InputStream) extends BufferedInputStream(in) {
private val singleByte = new Array[Byte](1)
override def read(): Int = synchronized {
val r = read(singleByte)
if (r < 0) r
else singleByte(0).toInt & 0xff
}
} |
…ive#1922) `read()` should return a value between `-1` and `255` and `-1` means `EOF`.
…ive#1922) `read()` should return a value between `-1` and `255` and `-1` means `EOF`.
read()
should return a value between-1
and255
and-1
meansEOF
.When
buf(pos)
contains value bigger than0x7f
for example171.toByte
and makes.toInt
, it converts this value to-85
that can be regarded by enduser asEOF
if he uses< 0
condition.Unfortunately this bug hasn't got workaround on user side because when stream contains
0xff
, theread()
returns-1
and it is impossibly to distinguish theEOF
and0xff
.