crash fix after memory leak
This commit is contained in:
@@ -55,7 +55,7 @@ export default class Stream {
|
||||
public writeBoolean(value: boolean) {
|
||||
this.writeBit(value ? 1 : 0);
|
||||
}
|
||||
|
||||
|
||||
public readBoolean(): boolean {
|
||||
return this.readBit() === 1;
|
||||
}
|
||||
@@ -80,6 +80,19 @@ export default class Stream {
|
||||
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) {
|
||||
const buffer = new ArrayBuffer(4);
|
||||
new DataView(buffer).setFloat32(0, value, true);
|
||||
@@ -94,19 +107,6 @@ export default class Stream {
|
||||
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) {
|
||||
let length = value.length;
|
||||
this.writeInt32(length);
|
||||
@@ -117,6 +117,14 @@ export default class Stream {
|
||||
|
||||
public readString(): string {
|
||||
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 = "";
|
||||
for (let i = 0; i < length; i++) {
|
||||
value += String.fromCharCode(this.readInt16());
|
||||
|
||||
Reference in New Issue
Block a user