Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unreachable program point in zend_hash #17187

Open
chongwick opened this issue Dec 17, 2024 · 4 comments · May be fixed by #17205
Open

unreachable program point in zend_hash #17187

chongwick opened this issue Dec 17, 2024 · 4 comments · May be fixed by #17205

Comments

@chongwick
Copy link

Description

The following code:

<?php
class ImmutableParser {
    private $parser;
    private $immutableData;

    public function __construct() {
        $this->parser = xml_parser_create();
        xml_set_element_handler($this->parser, function ($parser, $name, $attrs) {
            echo "open\n";
            var_dump($name, $attrs);
            $this->immutableData = array();
        }, function ($parser, $name) {
            echo "close\n";
            var_dump($name);
        });
    }

    public function parseXml($xml) {
        $this->immutableData = array();
        xml_parse_into_struct($this->parser, $xml, $this->immutableData, $this->immutableData);
        return $this->immutableData;
    }
}
$immutableParser = new ImmutableParser();
$xml = "<container><child/></container>";
$immutableData = $immutableParser->parseXml($xml);
?>

Resulted in this output:

/home/dan/php-src/Zend/zend_hash.c:807:3: runtime error: execution reached an unreachable program point

ZEND_ASSERT(idx < HT_IDX_TO_HASH(ht->nTableSize));

PHP Version

8.4.1

Operating System

Ubuntu 22.04

@devnexen
Copy link
Member

I hit this condition instead

/home/dcarlier/Contribs/php-src/Zend/zend_hash.c(1090) : ht=0x7ff72424b6c0 is already destroyed
php: /home/dcarlier/Contribs/php-src/Zend/zend_hash.c:74: void _zend_is_inconsistent(const HashTable *, const char *, int): Assertion `0' failed.
Aborted

nielsdos added a commit to nielsdos/php-src that referenced this issue Dec 17, 2024
A bunch of different issues:
1) The referenced value is copied without incrementing the refcount.
   The reason the refcount isn't incremented is because otherwise
   the array modifications would violate the RC1 constraints.
   Solve this by copying the reference itself instead and always
   read the referenced value.
2) No type checks on the array data, so malicious scripts could
   cause type confusion bugs.
3) Potential overflow when the arrays resize and we access ctag.
@nielsdos nielsdos linked a pull request Dec 17, 2024 that will close this issue
@chongwick
Copy link
Author

@nielsdos would this be a type of bug that could be assigned a CVE or no?

@nielsdos
Copy link
Member

I don't think so.
The bug is triggered because the element handler destroys the input array on callback. The attack model we use is that of a remote attacker in a webserver context, so there is no way for them to pull this off (i.e. the code has to be written in a malicious way).

@chongwick
Copy link
Author

Understood. I do appreciate all of your feedback.

nielsdos added a commit to nielsdos/php-src that referenced this issue Dec 19, 2024
A bunch of different issues:
1) The referenced value is copied without incrementing the refcount.
   The reason the refcount isn't incremented is because otherwise
   the array modifications would violate the RC1 constraints.
   Solve this by copying the reference itself instead and always
   read the referenced value.
2) No type checks on the array data, so malicious scripts could
   cause type confusion bugs.
3) Potential overflow when the arrays resize and we access ctag.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants