weechat-protocol.js: stricter slicing and type checking

This commit is contained in:
Philippe Proulx 2013-10-05 19:10:03 -04:00
parent f05fb72aaa
commit 187f22036b

View file

@ -70,6 +70,10 @@ WeeChatProtocol.prototype = {
_getType: function() { _getType: function() {
var t = this._getSlice(3); var t = this._getSlice(3);
if (!t) {
return null;
}
return WeeChatProtocol._uia2s(new Uint8Array(t)); return WeeChatProtocol._uia2s(new Uint8Array(t));
}, },
@ -347,6 +351,10 @@ WeeChatProtocol.prototype = {
* @return Sliced array * @return Sliced array
*/ */
_getSlice: function(length) { _getSlice: function(length) {
if (this.dataAt + length > this._data.byteLength) {
return null;
}
var slice = this._data.slice(this._dataAt, this._dataAt + length); var slice = this._data.slice(this._dataAt, this._dataAt + length);
this._dataAt += length; this._dataAt += length;