-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
java.nio.BufferUnderflowException #847
Comments
Could you reproduce this with Chrome? Thanks! |
Yes I get the same exception with Chrome (version 71.0.3578.98) |
Interesting... can you give us a link to your client side source code? |
This is my simple html client side code Click to expand<!DOCTYPE html>
<html>
<head>
<style>
#messages {
text-align: left;
width: 50%;
padding: 1em;
border: 1px solid black;
}
</style>
<title>WebSocket Client</title>
</head>
<body>
<div class="container">
<div id="messages" class="messages"></div>
<div class="input-fields">
<p>Type a message and hit send:</p>
<input id="message"/>
<button id="send">Send</button>
<p>Select an image and hit send:</p>
<input type="file" id="file" accept="image/*"/>
<button id="sendImage">Send Image</button>
</div>
</div>
</body>
<script>
const messageWindow = document.getElementById("messages");
const sendButton = document.getElementById("send");
const messageInput = document.getElementById("message");
const fileInput = document.getElementById("file");
const sendImageButton = document.getElementById("sendImage");
const socket = new WebSocket("ws://localhost:8080");
socket.binaryType = "arraybuffer";
socket.onopen = function (event) {
addMessageToWindow("Connected");
};
socket.onmessage = function (event) {
if (event.data instanceof ArrayBuffer) {
addMessageToWindow("Got Image:");
addImageToWindow(event.data);
} else {
addMessageToWindow("Got Message: " + event.data);
}
};
sendButton.onclick = function (event) {
sendMessage(messageInput.value);
messageInput.value = "";
};
sendImageButton.onclick = function (event) {
var reader = new FileReader();
reader.onload = function() {
sendMessage(this.result);
};
reader.readAsArrayBuffer(fileInput.files[0]);
fileInput.value = null;
};
function sendMessage(message) {
socket.send(message);
addMessageToWindow("Sent Message: " + message);
}
function addMessageToWindow(message) {
messageWindow.innerHTML += "<div>" + message + "</div>";
}
function addImageToWindow(image) {
let url = URL.createObjectURL(new Blob([image]));
messageWindow.innerHTML += "<img src='" + url + "'/>";
}
</script>
</html> |
I can't reproduce this behaviour. I can successfully upload & download images of size over 40 MB. I'd appreciate if you could post the following details:
|
Was able to reproduce this with 65.0-64 bit running against the ChatServer example using your avatar image @PhilipRoman (https://avatars2.githubusercontent.com/u/33231208?s=400&v=4) Worked best when trying to upload the same image multiple times Only affects Firefox currently as it seems.. |
Very strange. I've tried on Java 8 and Java 11; on Chrome 71.0.3578.98, Firefox Quantum 64.0.2 (64-bit), MS Edge with my avatar and loads of other files I could find, but none of them triggered the error. |
Looks like the bug cause is #805, in detail my refactoring of translateSingleFramePayloadLength (call by value instead of reference for realpacketsize). |
@nalizadeh could you confirm that this only affects 1.4.0? Best regards, |
Looks like it happens only on 1.4.0 (I was previously testing on 1.3.9)! I tested on library version 1.4.0 and it fails reliably. The issue is not related to client side and can be reproduced by sending a byte buffer from JWS client.
If in step 3 the buffer size is 1, the following error occurs instead:
|
specific image file which causes it to fail server side code java version & Java-WebSocket library version could you confirm that this only affects 1.4.0? Good luck with bug fixing! :) |
Fixing this tonight! |
Now that's solved for me, many Thanks :) |
Hello community,
I am not sure if this is a bug or a mistake of mine. I'm trying to upload images from an HTML page, it works quite well with small images (max size = 16kb), but with large images the server throws the exception java.nio.BufferUnderflowException.
Is there a way to increase the frame capacity here?
I use the Firefox Quantum as a browser.
The text was updated successfully, but these errors were encountered: