php / php/php-src

stack overflow in array/sanitizer

Open
#23,112 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Extension: standard Status: Needs Triage
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

The following code:

<?php
$a=[]; for($i=0;$i<1000000;$i++){$a=['k'=>$a];}
$b=array_merge_recursive($a,$a);

Resulted in this output:

    #226 0x55fe77cec009 in php_array_merge_recursive /home/php-src/ext/standard/array.c:3975
    #227 0x55fe77cec009 in php_array_merge_recursive /home/php-src/ext/standard/array.c:3975
    #228 0x55fe77cec009 in php_array_merge_recursive /home/php-src/ext/standard/array.c:3975
    #229 0x55fe77cec009 in php_array_merge_recursive /home/php-src/ext/standard/array.c:3975
    #230 0x55fe77cec009 in php_array_merge_recursive /home/php-src/ext/standard/array.c:3975
    #231 0x55fe77cec009 in php_array_merge_recursive /home/php-src/ext/standard/array.c:3975
    #232 0x55fe77cec009 in php_array_merge_recursive /home/php-src/ext/standard/array.c:3975
    #233 0x55fe77cec009 in php_array_merge_recursive /home/php-src/ext/standard/array.c:3975
    #234 0x55fe77cec009 in php_array_merge_recursive /home/php-src/ext/standard/array.c:3975
    #235 0x55fe77cec009 in php_array_merge_recursive /home/php-src/ext/standard/array.c:3975
    #236 0x55fe77cec009 in php_array_merge_recursive /home/php-src/ext/standard/array.c:3975
    #237 0x55fe77cec009 in php_array_merge_recursive /home/php-src/ext/standard/array.c:3975
    #238 0x55fe77cec009 in php_array_merge_recursive /home/php-src/ext/standard/array.c:3975
    #239 0x55fe77cec009 in php_array_merge_recursive /home/php-src/ext/standard/array.c:3975
    #240 0x55fe77cec009 in php_array_merge_recursive /home/php-src/ext/standard/array.c:3975
    #241 0x55fe77cec009 in php_array_merge_recursive /home/php-src/ext/standard/array.c:3975
    #242 0x55fe77cec009 in php_array_merge_recursive /home/php-src/ext/standard/array.c:3975
    #243 0x55fe77cec009 in php_array_merge_recursive /home/php-src/ext/standard/array.c:3975
    #244 0x55fe77cec009 in php_array_merge_recursive /home/php-src/ext/standard/array.c:3975
    #245 0x55fe77cec009 in php_array_merge_recursive /home/php-src/ext/standard/array.c:3975
    #246 0x55fe77cec009 in php_array_merge_recursive /home/php-src/ext/standard/array.c:3975
    #247 0x55fe77cec009 in php_array_merge_recursive /home/php-src/ext/standard/array.c:3975
    #248 0x55fe77cec009 in php_array_merge_recursive /home/php-src/ext/standard/array.c:3975
    #249 0x55fe77cec009 in php_array_merge_recursive /home/php-src/ext/standard/array.c:3975

SUMMARY: AddressSanitizer: stack-overflow ../../../../src/libsanitizer/asan/asan_stack.cpp:63 in __sanitizer::BufferedStackTrace::UnwindImpl(unsigned long, unsigned long, void*, bool, unsigned int)
==26==ABORTING
USE_ZEND_ALLOC=0 php poc.php
PHP Version
8.6.0
Operating System

ubuntu 22.04

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproducer in the issue and inspect php_array_merge_recursive at ext/standard/array.c:3975. Run it under AddressSanitizer with USE_ZEND_ALLOC=0, then add a regression test covering the nested array_merge_recursive case; done means the reproducer no longer causes a stack overflow.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, php
Domain
backend, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.