Nested unserialize() can expose an outer object while its __unserialize() data is still being parsed

Aberta
#25,056 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
5/5
Tempo estimado
Mais de uma semana
Facilidade para iniciantes
25/100
Tipo de issue
Bug
Clareza
Precisa de esclarecimento
Status de atividade
Ativa
Stack de tecnologia
c, php
Domínio
backend, security

Direção de pesquisa

The issue provides a PHP reproducer that triggers the bug in php-src's unserialize. Investigate the C parser handling nested unserialize calls and shared reference tables; no specific files are named. A fix requires a design decision on rejecting references versus preserving cyclic payloads, and validation with the reproducer.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

Description

A nested unserialize() call from Serializable::unserialize() shares the outer reference table. An r/R record can therefore resolve to an outer object whose __unserialize() data is still being parsed. At that point __unserialize() has not been queued and cannot be called because the outer parser frame is suspended.

If inner code only stores the object, identity is preserved and it is initialized later. If it accesses the object immediately, it observes incomplete userland properties and could reach uninitialized native state for internal classes.

Unlike GH-19860, this object is not fully parsed, so finishing pending callbacks at the nested boundary cannot fix this case.

Reproducer
<?php
class Outer {
    public string $value;

    public function __unserialize(array $data): void {
        $this->value = "ready";
    }
}

class Legacy implements Serializable {
    public function serialize(): string {
        return "";
    }

    public function unserialize(string $data): void {
        $object = unserialize($data);
        var_dump(isset($object->value));
    }

    public function __serialize(): array {
        return [];
    }

    public function __unserialize(array $data): void {}
}

$result = unserialize("O:5:\"Outer\":1:{i:0;C:6:\"Legacy\":4:{r:1;}}");
echo $result->value, "\n";

Output:

bool(false)
ready
Expected behavior

This needs a separate design decision. Rejecting these references prevents unsafe access, but breaks cyclic payloads that previously retained the object until initialization completed.

Linguagem predominante
C
Estrelas
41.8k
Forks
8.5k
Merge médio
2d 12h
PRs com merge (30d)
137

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de php/php-src

Todas as issues de php/php-src

Issues semelhantes

Mais issues de C

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.