diff --git a/td/mtproto/HandshakeConnection.h b/td/mtproto/HandshakeConnection.h index 5c9341dd..fb8d74c7 100644 --- a/td/mtproto/HandshakeConnection.h +++ b/td/mtproto/HandshakeConnection.h @@ -73,7 +73,8 @@ class HandshakeConnection } packet.confirm_read(12); - TRY_STATUS(handshake_->on_message(packet.as_slice(), this, context_.get())); + auto fixed_packet_size = packet.size() & ~3; // remove some padded data + TRY_STATUS(handshake_->on_message(packet.as_slice().truncate(fixed_packet_size), this, context_.get())); return Status::OK(); } }; diff --git a/td/mtproto/Transport.cpp b/td/mtproto/Transport.cpp index 0e65c82e..738938c2 100644 --- a/td/mtproto/Transport.cpp +++ b/td/mtproto/Transport.cpp @@ -98,6 +98,7 @@ Status Transport::read_crypto_impl(int X, MutableSlice message, const AuthKey &a auto *header = &as(message.begin()); *header_ptr = header; auto to_decrypt = MutableSlice(header->encrypt_begin(), message.uend()); + to_decrypt = to_decrypt.truncate(to_decrypt.size() & ~15); if (to_decrypt.size() % 16 != 0) { return Status::Error(PSLICE() << "Invalid mtproto message: size of encrypted part is not multiple of 16 [size=" << to_decrypt.size() << "]"); @@ -287,7 +288,7 @@ Result Transport::read_auth_key_id(Slice message) { Status Transport::read(MutableSlice message, const AuthKey &auth_key, PacketInfo *info, MutableSlice *data, int32 *error_code) { if (message.size() < 8) { - if (message.size() == 4) { + if (message.size() >= 4) { *error_code = as(message.begin()); return Status::OK(); }