Fixes #9006 - WebSocket MessageInputStream.read() returns signed byte
Now properly coverting to `int`. Added test. Also fixed MultiPartInputStreamParser.Base64InputStream for the same issue. Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
parent
390abcccf2
commit
a546027db8
|
@ -941,7 +941,7 @@ public class MultiPartInputStreamParser
|
|||
_pos = 0;
|
||||
}
|
||||
|
||||
return _buffer[_pos++];
|
||||
return _buffer[_pos++] & 0xFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ public class MessageInputStream extends InputStream implements MessageSink
|
|||
if (len < 0) // EOF
|
||||
return -1;
|
||||
if (len > 0) // did read something
|
||||
return buf[0];
|
||||
return buf[0] & 0xFF;
|
||||
// reading nothing (len == 0) tries again
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.junit.jupiter.api.Test;
|
|||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTimeout;
|
||||
|
||||
|
@ -279,4 +280,23 @@ public class MessageInputStreamTest
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadSingleByteIsNotSigned() throws Exception
|
||||
{
|
||||
try (MessageInputStream stream = new MessageInputStream())
|
||||
{
|
||||
// Byte must be greater than 127.
|
||||
int theByte = 200;
|
||||
// Append a single message (simple, short)
|
||||
Frame frame = new Frame(OpCode.BINARY);
|
||||
frame.setPayload(new byte[]{(byte)theByte});
|
||||
frame.setFin(true);
|
||||
stream.accept(frame, Callback.NOOP);
|
||||
|
||||
// Single byte read must not return a signed byte.
|
||||
int read = stream.read();
|
||||
assertEquals(theByte, read);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue