Skip to content

Quoted-printable filter underflows icnt and reads past the input window #25956

Todo

Description

@kid-lxy

Description

The following code:

<?php
$s = tmpfile();
fwrite($s, "abc ");
rewind($s);
stream_filter_append($s, 'convert.quoted-printable-encode', STREAM_FILTER_READ, [
    'line-break-chars' => " X",
    'line-length' => 76,
]);
var_dump(bin2hex(stream_get_contents($s)));
fclose($s);

Resulted in this output:

string(8) "61626320"

But I expected this output instead:

string(12) "6162633d3230"

After the trailing space partially matches the custom line-break prefix, ext/standard/filters.c:700 leaves icnt == 0, but pending-prefix processing reaches the lookahead at lines 741-745. There j = icnt - 1 underflows to SIZE_MAX and *ps2 is read at the logical input end; the lookahead requires an icnt > 0 guard, and the trailing space should be encoded normally as abc=20 without that out-of-window read.

PHP Version

PHP 8.7.0-dev (cli) (built: Nov 29 2026 03:42:09) (NTS)
Copyright © The PHP Group and Contributors
Zend Engine v4.7.0-dev, Copyright © Zend by Perforce
    with Zend OPcache v8.7.0-dev, Copyright ©, by Zend by Perforce

Operating System

Ubuntu 24.04.5 LTS

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