Fixed deserialization of Object constructors containing vectors (why are the even serialized without their type?)
This commit is contained in:
parent
d41b58827e
commit
c90e353345
@ -121,7 +121,7 @@ trait MessageHandler
|
|||||||
} else {
|
} else {
|
||||||
throw new \danog\MadelineProto\SecurityException('Got unknown auth_key id');
|
throw new \danog\MadelineProto\SecurityException('Got unknown auth_key id');
|
||||||
}
|
}
|
||||||
$deserialized = $this->deserialize($message_data, ['type' => '']);
|
$deserialized = $this->deserialize($message_data, ['type' => '', 'datacenter' => $datacenter]);
|
||||||
$this->datacenter->sockets[$datacenter]->incoming_messages[$message_id]['content'] = $deserialized;
|
$this->datacenter->sockets[$datacenter]->incoming_messages[$message_id]['content'] = $deserialized;
|
||||||
$this->datacenter->sockets[$datacenter]->incoming_messages[$message_id]['response'] = -1;
|
$this->datacenter->sockets[$datacenter]->incoming_messages[$message_id]['response'] = -1;
|
||||||
$this->datacenter->sockets[$datacenter]->new_incoming[$message_id] = $message_id;
|
$this->datacenter->sockets[$datacenter]->new_incoming[$message_id] = $message_id;
|
||||||
|
@ -28,7 +28,7 @@ trait SeqNoHandler
|
|||||||
|
|
||||||
public function check_in_seq_no($datacenter, $current_msg_id)
|
public function check_in_seq_no($datacenter, $current_msg_id)
|
||||||
{
|
{
|
||||||
if (isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['seq_no']) && ($seq_no = $this->generate_in_seq_no($datacenter, $this->content_related($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['_']))) !== $this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['seq_no']) {
|
if (isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['seq_no']) && ($seq_no = $this->generate_in_seq_no($datacenter, $this->content_related($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']))) !== $this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['seq_no']) {
|
||||||
\danog\MadelineProto\Logger::log(['SECURITY WARNING: Seqno mismatch (should be '.$seq_no.', is '.$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['seq_no'].', '.$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['_'].')'], \danog\MadelineProto\Logger::ERROR);
|
\danog\MadelineProto\Logger::log(['SECURITY WARNING: Seqno mismatch (should be '.$seq_no.', is '.$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['seq_no'].', '.$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['_'].')'], \danog\MadelineProto\Logger::ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -44,9 +44,9 @@ trait SeqNoHandler
|
|||||||
|
|
||||||
public function content_related($method)
|
public function content_related($method)
|
||||||
{
|
{
|
||||||
//var_dump($method);
|
|
||||||
return !in_array(
|
return isset($method['_']) ? !in_array(
|
||||||
$method,
|
$method['_'],
|
||||||
[
|
[
|
||||||
'rpc_result',
|
'rpc_result',
|
||||||
// 'rpc_error',
|
// 'rpc_error',
|
||||||
@ -79,6 +79,6 @@ trait SeqNoHandler
|
|||||||
'msg_resend_req',
|
'msg_resend_req',
|
||||||
'msg_resend_ans_req',
|
'msg_resend_ans_req',
|
||||||
]
|
]
|
||||||
);
|
) : true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -500,7 +500,7 @@ trait TL
|
|||||||
}
|
}
|
||||||
switch ($constructorData['predicate']) {
|
switch ($constructorData['predicate']) {
|
||||||
case 'gzip_packed':
|
case 'gzip_packed':
|
||||||
return $this->deserialize(gzdecode($this->deserialize($bytes_io, ['type' => 'bytes'])));
|
return $this->deserialize(gzdecode($this->deserialize($bytes_io, ['type' => 'bytes', 'datacenter' => $type['datacenter']])), ['type' => '', 'datacenter' => $type['datacenter']]);
|
||||||
case 'Vector t':
|
case 'Vector t':
|
||||||
case 'vector':
|
case 'vector':
|
||||||
break;
|
break;
|
||||||
@ -534,7 +534,15 @@ trait TL
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($constructorData['predicate'] === 'gzip_packed') {
|
if ($constructorData['predicate'] === 'gzip_packed') {
|
||||||
return $this->deserialize(gzdecode($this->deserialize($bytes_io, ['type' => 'bytes'])));
|
if (!isset($type['subtype'])) $type['subtype'] = '';
|
||||||
|
return $this->deserialize(gzdecode($this->deserialize($bytes_io, ['type' => 'bytes'])), ['type' => '', 'datacenter' => $type['datacenter'], 'subtype' => $type['subtype']]);
|
||||||
|
}
|
||||||
|
if ($constructorData['type'] === 'Vector t') {
|
||||||
|
|
||||||
|
$constructorData['datacenter'] = $type['datacenter'];
|
||||||
|
$constructorData['subtype'] = $type['subtype'];
|
||||||
|
$constructorData['type'] = 'vector';
|
||||||
|
return $this->deserialize($bytes_io, $constructorData);
|
||||||
}
|
}
|
||||||
$x = ['_' => $constructorData['predicate']];
|
$x = ['_' => $constructorData['predicate']];
|
||||||
foreach ($constructorData['params'] as $arg) {
|
foreach ($constructorData['params'] as $arg) {
|
||||||
@ -561,6 +569,12 @@ trait TL
|
|||||||
if (in_array($arg['name'], ['msg_ids', 'msg_id', 'bad_msg_id', 'req_msg_id', 'answer_msg_id', 'first_msg_id', 'key_fingerprint', 'server_salt', 'new_server_salt', 'server_public_key_fingerprints', 'ping_id', 'exchange_id'])) {
|
if (in_array($arg['name'], ['msg_ids', 'msg_id', 'bad_msg_id', 'req_msg_id', 'answer_msg_id', 'first_msg_id', 'key_fingerprint', 'server_salt', 'new_server_salt', 'server_public_key_fingerprints', 'ping_id', 'exchange_id'])) {
|
||||||
$arg['strlong'] = true;
|
$arg['strlong'] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($x['_'] === 'rpc_result' && $arg['name'] === 'result' && isset($this->datacenter->sockets[$type['datacenter']]->new_outgoing[$x['req_msg_id']]['type']) && stripos($this->datacenter->sockets[$type['datacenter']]->new_outgoing[$x['req_msg_id']]['type'], '<') !== false) {
|
||||||
|
|
||||||
|
$arg['subtype'] = preg_replace(['|Vector[<]|', '|[>]|'], '', $this->datacenter->sockets[$type['datacenter']]->new_outgoing[$x['req_msg_id']]['type']);
|
||||||
|
}
|
||||||
|
$arg['datacenter'] = $type['datacenter'];
|
||||||
$x[$arg['name']] = $this->deserialize($bytes_io, $arg);
|
$x[$arg['name']] = $this->deserialize($bytes_io, $arg);
|
||||||
if ($arg['name'] === 'random_bytes') {
|
if ($arg['name'] === 'random_bytes') {
|
||||||
if (strlen($x[$arg['name']]) < 15) {
|
if (strlen($x[$arg['name']]) < 15) {
|
||||||
|
@ -69,14 +69,16 @@ $message = (getenv('TRAVIS_COMMIT') == '') ? 'I iz works always (io laborare sem
|
|||||||
echo 'Serializing MadelineProto to session.madeline...'.PHP_EOL;
|
echo 'Serializing MadelineProto to session.madeline...'.PHP_EOL;
|
||||||
echo 'Wrote '.\danog\MadelineProto\Serialization::serialize('session.madeline', $MadelineProto).' bytes'.PHP_EOL;
|
echo 'Wrote '.\danog\MadelineProto\Serialization::serialize('session.madeline', $MadelineProto).' bytes'.PHP_EOL;
|
||||||
echo 'Size of MadelineProto instance is '.strlen(serialize($MadelineProto)).' bytes'.PHP_EOL;
|
echo 'Size of MadelineProto instance is '.strlen(serialize($MadelineProto)).' bytes'.PHP_EOL;
|
||||||
/*
|
|
||||||
|
|
||||||
$call = $MadelineProto->API->request_call(getenv('TEST_SECRET_CHAT'));
|
$call = $MadelineProto->API->request_call(getenv('TEST_SECRET_CHAT'));
|
||||||
|
|
||||||
echo 'Waiting for '.getenv('TEST_SECRET_CHAT').' to accept the call...'.PHP_EOL;
|
echo 'Waiting for '.getenv('TEST_SECRET_CHAT').' to accept the call...'.PHP_EOL;
|
||||||
while ($MadelineProto->call_status($call) !== $MadelineProto->API->READY) {
|
while ($MadelineProto->call_status($call) !== $MadelineProto->API->READY) {
|
||||||
$MadelineProto->get_updates();
|
$MadelineProto->get_updates();
|
||||||
}
|
}
|
||||||
var_dump($MadelineProto->get_call($call));
|
var_dump($MadelineProto->get_call($call));
|
||||||
*/
|
|
||||||
$secret = $MadelineProto->API->request_secret_chat(getenv('TEST_SECRET_CHAT'));
|
$secret = $MadelineProto->API->request_secret_chat(getenv('TEST_SECRET_CHAT'));
|
||||||
echo 'Waiting for '.getenv('TEST_SECRET_CHAT').' to accept the secret chat...'.PHP_EOL;
|
echo 'Waiting for '.getenv('TEST_SECRET_CHAT').' to accept the secret chat...'.PHP_EOL;
|
||||||
while ($MadelineProto->secret_chat_status($secret) !== 2) {
|
while ($MadelineProto->secret_chat_status($secret) !== 2) {
|
||||||
|
Loading…
Reference in New Issue
Block a user