Skip to content

User filters allow breaking typed properties #20370

@ndossche

Description

@ndossche

Description

The following code:

<?php

class pass_filter
{
    public $filtername;
    public $params;
    public int $stream = 1;

    function filter($in, $out, &$consumed, $closing): int
    {
        while ($bucket=stream_bucket_make_writeable($in)) {
            $consumed += $bucket->datalen;
            stream_bucket_append($out, $bucket);
        }
        var_dump($this->stream); // resource instead of int -> type system violation
        return PSFS_PASS_ON;
    }
}

stream_filter_register("pass", "pass_filter");
$fp=fopen("php://memory", "w");
stream_filter_append($fp,  "pass");
fwrite($fp, "Thank you\n");
rewind($fp);
echo fread($fp, 1024);

Resulted in this output:

resource(5) of type (stream)
resource(5) of type (stream)
resource(5) of type (stream)
resource(5) of type (stream)
Thank you
resource(5) of type (Unknown)

But I expected this output instead:

An exception, because the property shouldn't have been set in the first place. The type system should prevent this.

I discovered this because I wanted to get rid of the OBJPROP accessor, which would avoid building the properties table. It's a bit annoying to fix this as you'd need to conditionally use zend_update_property

PHP Version

8.3+

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions