ArrayObject backing storage cycle causes unbounded recursion in spl_array_get_hash_table_ptr()
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 51/100
Direção de pesquisa
Start in ext/spl/spl_array.c, especially spl_array_set_array() and spl_array_get_hash_table_ptr(), and trace how SPL_ARRAY_USE_OTHER follows ArrayObject or ArrayIterator backing storage. Check existing SPL tests for exchangeArray() and constructor behavior, then add coverage showing that creating a multi-object backing cycle raises an error without recursion; verify ordinary backing objects still work.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Description
ArrayObject::exchangeArray() (and the constructor) accept another ArrayObject as backing storage and only reject an object backing itself. Two objects that back each other are accepted silently, and the first operation that needs the storage recurses without limit in spl_array_get_hash_table_ptr() until the process crashes.
The following code:
<?php
$a = new ArrayObject([1]);
$b = new ArrayObject($a); // $b uses $a's storage
$a->exchangeArray($b); // $a now uses $b's storage: a cycle
echo "cycle built\n";
var_dump(count($a));
Resulted in this output (AddressSanitizer build):
==ERROR: AddressSanitizer: stack-overflow on address ...
#0 spl_array_get_hash_table_ptr ext/spl/spl_array.c:65
#1 spl_array_get_hash_table_ptr ext/spl/spl_array.c:71
#2 spl_array_get_hash_table_ptr ext/spl/spl_array.c:71
...
But I expected this output instead: an error when the cycle is created (for example an InvalidArgumentException from exchangeArray()), as for other unsupported backing objects.
spl_array_set_array() sets SPL_ARRAY_USE_OTHER for any other ArrayObject/ArrayIterator and only special-cases Z_OBJ_P(object) == Z_OBJ_P(array); following the chain of SPL_ARRAY_USE_OTHER objects before accepting one would catch longer cycles too. Object backing storage is deprecated on master, but it is still accepted there.
Reproduced on 8.2.34-dev (512c04e39f) and 8.4.28-dev; the same code is on master.
This issue was found by an LLM-Enhanced Static Analysis Engine and verified manually.
PHP Version
PHP 8.4.28-dev, PHP 8.2.34-dev
Operating System
Linux (Ubuntu 20.04, x86_64)
- Linguagem predominante
- C
- Estrelas
- 41.8k
- Forks
- 8.5k
- Merge médio
- 2d 13h
- PRs com merge (30d)
- 145
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de php/php-src
-
ext/openssl: 8.2.31+/8.3.31+ fail to build against OpenSSL 1.0.2 (ASN1_STRING_get0_data in xp_ssl.c)Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 79/100
Mantenedores costumam responder em até 1 dia
-
Bug Status: Needs Triage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
php/php-src#25397 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
SNMP accepts malformed remote portsTalvez já em andamento Um pull request vinculado a esta issue está aberto ou já foi mesclado. Aberta
Dificuldade 2/5 Meio dia Facilidade para iniciantes 62/100
php/php-src#25137 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Bug Status: Needs Triage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 64/100
Mantenedores costumam responder em até 1 dia
-
quoted_printable_encode() produces lines longer than 76 characters for bytes 0xF5 to 0xFFTalvez já em andamento Um pull request vinculado a esta issue está aberto ou já foi mesclado. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
Mantenedores costumam responder em até 1 dia
Todas as issues de php/php-src
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
-
not for AI lovers
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
OSGeo/gdal#15515 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Template: Bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 83/100
betaflight/betaflight#16014 ·
Mantenedores costumam responder em até 3 dias
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 75/100
ly05010419/MacNativeGames#2119 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100