Skip to content

Segmentation fault in RecursiveIteratorIterator->current() with a xml element input #16808

Closed

Description

@YuanchengJiang

Description

The following code:

<?php
$sx1 = new SimpleXMLElement("<root />");
$fusion = $sx1;
$test = new RecursiveIteratorIterator($fusion);
var_dump($test->current());

Resulted in this output:

/php-src/main/spprintf.c:376:14: runtime error: member access within null pointer of type 'zend_string' (aka 'struct _zend_string')

To reproduce: JIT 1015

PHP Version

nightly

Operating System

ubuntu 22.04

Activity

  1. ndossche commented on Nov 15, 2024

    @ndossche
    Member

    It already goes wrong in non-JIT mode:

    Fatal error: RecursiveIteratorIterator::current(): Return value must be of type mixed, null returned in Unknown on line 0
    

    So the mixed type check for null isn't working properly apparently. But only for internal functions, userland functions seem fine... EDIT: actually on a release build it outputs "UNKNOWN:0" so that means an UNDEF value is produced somewhere and propagated...

  2. ndossche commented on Nov 15, 2024

    @ndossche
    Member

    This is not a JIT nor opcache issue, the SXE iterator returns UNDEF when invalid (which is right EDIT: hmm or not will need to check) but SPL does not handle this right. Either it should check for validity first or check if the return value is UNDEF.

  3. ndossche commented on Nov 15, 2024

    @ndossche
    Member

    Okay judging how the other code works: the issue is that SXE returns UNDEF but it should return NULL; that's how others do it too. So this is an SXE bug after all.

  4. self-assigned this
    on Nov 15, 2024
  5. added a commit that references this issue on Nov 15, 2024
    8e00e46
  6. added 3 commits that reference this issue on Nov 16, 2024
    fbb0061
    2ba1859
    d3fada3
  7. added a commit that references this issue on Nov 16, 2024
    cfc8361
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions