Permalink
Browse files

Fix packets containing 0x00 bytes getting truncated after the first 0…

…x00 byte.
  • Loading branch information...
1 parent 8e46ce3 commit 1f87fc2dd73b5a8a1211de076d308f78de23ef79 @BonsaiDen BonsaiDen committed Sep 25, 2010
Showing with 12 additions and 3 deletions.
  1. BIN WebSocketMain.swf
  2. BIN WebSocketMainInsecure.zip
  3. +10 −1 flash-src/WebSocket.as
  4. +2 −2 web_socket.js
View
Binary file not shown.
View
Binary file not shown.
View
@@ -278,7 +278,16 @@ public class WebSocket extends EventDispatcher {
return;
}
buffer.position = 1;
- var data:String = buffer.readUTFBytes(pos - 1);
+ var data:String = "";
+ for(var i:int = 1, zeroByte:String = String.fromCharCode(0x00); i <= pos; i++) {
+ if (buffer[i] == 0x00) {
+ data += buffer.readUTFBytes(pos - buffer.position) + zeroByte;
+ buffer.position = i + 1;
+
+ } else if (buffer[i] == 0xff) {
+ data += buffer.readUTFBytes(buffer.bytesAvailable - 1);
+ }
+ }
main.log("received: " + data);
dataQueue.push(encodeURIComponent(data));
dispatchEvent(new Event("message"));
View
@@ -209,10 +209,10 @@
try {
if (this.onmessage) {
var e;
- if (window.MessageEvent) {
+ if (window.MessageEvent && !window.opera) {
e = document.createEvent("MessageEvent");
e.initMessageEvent("message", false, false, data, null, null, window, null);
- } else { // IE
+ } else { // IE and Opera, the latter one truncates the data parameter after any 0x00 bytes
e = {data: data};
}
this.onmessage(e);

0 comments on commit 1f87fc2

Please sign in to comment.