[php-src] PR #22424: Fix stream filter flush corrupting a partially-read buffer
| From: | iliaal | Date: | Wed, 24 Jun 2026 11:22:09 +0000 |
| Subject: | [php-src] PR #22424: Fix stream filter flush corrupting a partially-read buffer | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-36590@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/22424
Author: iliaal
When a read filter is flushed (for example via stream_filter_remove()) while the stream has already
been partially read, _php_stream_filter_flush() backs the unconsumed tail of the read buffer up to
offset 0. Two defects in that block diverged from the equivalent code in streams.c. The copy used
memcpy() on source/destination ranges that overlap whenever writepos - readpos exceeds readpos,
which is undefined behavior (ASAN reports memcpy-param-overlap). And writepos was shrunk with
writepos -= readpos after readpos had already been zeroed, making the subtraction a no-op, so
writepos stayed inflated by readpos bytes: the stale tail was kept live and later flushed buckets
were appended past the real end, duplicating bytes and risking an out-of-bounds write. Use memmove()
and subtract before zeroing, matching streams.c. The block dates to the original
stream_filter_remove() commit (34550382d8) in 2004.