crash fix after memory leak
This commit is contained in:
@@ -80,6 +80,19 @@ export default class Stream {
|
|||||||
return value | this.readInt16();
|
return value | this.readInt16();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public writeInt64(value: number) {
|
||||||
|
const high = Math.floor(value / 0x100000000);
|
||||||
|
const low = value >>> 0;
|
||||||
|
this.writeInt32(high);
|
||||||
|
this.writeInt32(low);
|
||||||
|
}
|
||||||
|
|
||||||
|
public readInt64(): number {
|
||||||
|
const high = this.readInt32();
|
||||||
|
const low = this.readInt32() >>> 0;
|
||||||
|
return high * 0x100000000 + low;
|
||||||
|
}
|
||||||
|
|
||||||
public writeFloat32(value: number) {
|
public writeFloat32(value: number) {
|
||||||
const buffer = new ArrayBuffer(4);
|
const buffer = new ArrayBuffer(4);
|
||||||
new DataView(buffer).setFloat32(0, value, true);
|
new DataView(buffer).setFloat32(0, value, true);
|
||||||
@@ -94,19 +107,6 @@ export default class Stream {
|
|||||||
return new DataView(buffer).getFloat32(0, true);
|
return new DataView(buffer).getFloat32(0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public writeInt64(value: number) {
|
|
||||||
const high = Math.floor(value / 0x100000000);
|
|
||||||
const low = value >>> 0;
|
|
||||||
this.writeInt32(high);
|
|
||||||
this.writeInt32(low);
|
|
||||||
}
|
|
||||||
|
|
||||||
public readInt64(): number {
|
|
||||||
const high = this.readInt32();
|
|
||||||
const low = this.readInt32() >>> 0;
|
|
||||||
return high * 0x100000000 + low;
|
|
||||||
}
|
|
||||||
|
|
||||||
public writeString(value: string) {
|
public writeString(value: string) {
|
||||||
let length = value.length;
|
let length = value.length;
|
||||||
this.writeInt32(length);
|
this.writeInt32(length);
|
||||||
@@ -117,6 +117,14 @@ export default class Stream {
|
|||||||
|
|
||||||
public readString(): string {
|
public readString(): string {
|
||||||
let length = this.readInt32();
|
let length = this.readInt32();
|
||||||
|
/**
|
||||||
|
* Фикс уязвимости с длинной строки, превышающей
|
||||||
|
* возможность для чтения _stream
|
||||||
|
*/
|
||||||
|
if (length < 0 || length > (this._stream.length - (this._readPoiner >> 3))) {
|
||||||
|
console.info("Stream readString length invalid", length, this._stream.length, this._readPoiner);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
let value = "";
|
let value = "";
|
||||||
for (let i = 0; i < length; i++) {
|
for (let i = 0; i < length; i++) {
|
||||||
value += String.fromCharCode(this.readInt16());
|
value += String.fromCharCode(this.readInt16());
|
||||||
|
|||||||
Reference in New Issue
Block a user