nilesh74 / sipml5

Automatically exported from code.google.com/p/sipml5
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

ArrayBufferView size is not a small enough positive integer. #24

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago

Canary: 21.0.1137.1 Windows Vista
Version: r49 from svn

Call Stack:
Uncaught RangeError: ArrayBufferView size is not a small enough positive 
integer. tsk_buff.js:38
tsk_buff_ab2str tsk_buff.js:38
tsk_ragel_state_init_ai tsk_ragel.js:39
__tsip_transport_ws_onmessage tsip_transport.js:379

buff in tsk_buff_ab2str:
"SIP/2.0 401 Unauthorized
Via: SIP/2.0/WS 
df7jal23ls0d.invalid;branch=z9hG4bKv6Ac1PwQppgZOcqxawts6aha5GrW5Ikk;rport
From:  <sip:sipjs@officesip.local>;tag=ODbKBbENOA2LAoGxLabZ
To:  <sip:sipjs@officesip.local>;tag=2b249c78777846509921a74dbdb6530e
Call-ID: 52159381-973f-3120-c659-2293baeab1cb
CSeq: 61812 REGISTER
WWW-Authenticate: Digest 
realm="officesip.local",nonce="26cb330709fa2b663a488b0977873241",qop="auth",algo
rithm=MD5,stale=false,opaque="00000006"
x-Error-Details: No auth header
Content-Length: 0

"

Original issue reported on code.google.com by i...@fomine.com on 16 May 2012 at 2:58

GoogleCodeExporter commented 9 years ago
This issue is not relayted to the message content. The sipml5 does not accept 
websocket.opcode == Text frame, but...

http://tools.ietf.org/html/draft-ibc-sipcore-sip-websocket-02#section-4.2
WebSocket messages are carried on top of WebSocket UTF-8 text frames
or binary frames.  The SIP protocol [RFC3261] allows both text and
binary bodies in SIP messages.  Therefore SIP WebSocket Clients and
SIP WebSocket Servers MUST accept both WebSocket text and binary
frames.

Original comment by i...@fomine.com on 16 May 2012 at 8:46

GoogleCodeExporter commented 9 years ago
Possible solution:

function __tsip_transport_ws_onmessage_for_buffer(data) {
    var o_ragel_state = tsk_ragel_state_create();
    tsk_ragel_state_init_ai(o_ragel_state, data);
    var o_message = tsip_message.prototype.Parse(o_ragel_state, true);

    if (o_message) {
         //--console.debug("recv=%s", o_message.toString());
        o_message.o_socket = this;
        return this.o_transport.get_layer().handle_incoming_message(o_message);
    }
    else {
        console.error("Failed to parse message: %s", data);
        return -1;
    }
}

function __tsip_transport_ws_onmessage(evt) {
    console.debug("__tsip_transport_ws_onmessage");

    if(typeof(evt.data) == 'string') {
        var bb = new (window.MozBlobBuilder || window.WebKitBlobBuilder || window.BlobBuilder)();
        bb.append(evt.data);
        var f = new FileReader(bb.getBlob());
    f.websocket = this;
        f.onload = function(e) {
            __tsip_transport_ws_onmessage_for_buffer.call(f.websocket, e.target.result);
        }
        f.readAsArrayBuffer(bb.getBlob());
    }
    else {
        return __tsip_transport_ws_onmessage_for_buffer(evt.data);
    }
}

Original comment by i...@fomine.com on 16 May 2012 at 10:12

GoogleCodeExporter commented 9 years ago
The problem with "DOMString" is that SIP message will not be able to contain 
binary data while ArrayBuffer can contain both.
You don't need to write a new function. Try to change the ragel initializer
from:
tsk_ragel_state_init_ai(o_ragel_state, data);
to:
tsk_ragel_state_init_str(o_ragel_state, data);

Original comment by boss...@yahoo.fr on 16 May 2012 at 11:09

GoogleCodeExporter commented 9 years ago
>The problem with "DOMString" is that SIP message will not be able to contain 
binary

But sipml5 sends text blob itself. :)

>Try to change the ragel initializer from

Yes, it works! Thank you. Will you add it to project?

    if(typeof(evt.data) == 'string')
        tsk_ragel_state_init_str(o_ragel_state, evt.data);
    else
        tsk_ragel_state_init_ai(o_ragel_state, evt.data);

Original comment by i...@fomine.com on 17 May 2012 at 8:24

GoogleCodeExporter commented 9 years ago
Fixed by r54

Original comment by boss...@yahoo.fr on 17 May 2012 at 9:51