|
@@ -1,6 +1,6 @@
|
|
import { Connection, PacketCodec } from "./Connection";
|
|
import { Connection, PacketCodec } from "./Connection";
|
|
import { crc32 } from "../../Helpers";
|
|
import { crc32 } from "../../Helpers";
|
|
-import { InvalidChecksumError } from "../../errors";
|
|
|
|
|
|
+import { InvalidBufferError, InvalidChecksumError } from "../../errors";
|
|
import type { PromisedNetSockets, PromisedWebSockets } from "../../extensions";
|
|
import type { PromisedNetSockets, PromisedWebSockets } from "../../extensions";
|
|
|
|
|
|
export class FullPacketCodec extends PacketCodec {
|
|
export class FullPacketCodec extends PacketCodec {
|
|
@@ -40,6 +40,13 @@ export class FullPacketCodec extends PacketCodec {
|
|
return Buffer.alloc(0);
|
|
return Buffer.alloc(0);
|
|
}
|
|
}
|
|
const packetLen = packetLenSeq.readInt32LE(0);
|
|
const packetLen = packetLenSeq.readInt32LE(0);
|
|
|
|
+ if (packetLen < 0) {
|
|
|
|
+ // # It has been observed that the length and seq can be -429,
|
|
|
|
+ // # followed by the body of 4 bytes also being -429.
|
|
|
|
+ // # See https://github.com/LonamiWebs/Telethon/issues/4042.
|
|
|
|
+ const body = await reader.readExactly(4)
|
|
|
|
+ throw new InvalidBufferError(body);
|
|
|
|
+ }
|
|
let body = await reader.readExactly(packetLen - 8);
|
|
let body = await reader.readExactly(packetLen - 8);
|
|
const checksum = body.slice(-4).readUInt32LE(0);
|
|
const checksum = body.slice(-4).readUInt32LE(0);
|
|
body = body.slice(0, -4);
|
|
body = body.slice(0, -4);
|