php_embed_ub_write does not return on error
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
Description
sapi/embed/php_embed.c:
/* SAPIs only have unbuffered write operations. This is because PHP's output
* buffering feature will handle any buffering of the output and invoke the
* SAPI unbuffered write operation when it flushes the buffer.
*/
static size_t php_embed_ub_write(const char *str, size_t str_length)
{
const char *ptr = str;
size_t remaining = str_length;
size_t ret;
while (remaining > 0) {
ret = php_embed_single_write(ptr, remaining);
if (!ret) {
php_handle_aborted_connection();
}
ptr += ret;
remaining -= ret;
}
return str_length;
}
php_handle_aborted_connection does not always abort, i.e. if ignore_user_abort=1. So I sending fails and ret is 0, then remaining is never decremented and this loops forever.
It should probably return str_length - remaining after php_handle_aborted_connection().
PHP Version
master
Operating System
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in sapi/embed/php_embed.c at php_embed_ub_write and trace the php_embed_single_write error path followed by php_handle_aborted_connection. Verify that a zero-byte write cannot repeat indefinitely when the connection is not aborted. Done means the function returns the number of bytes written after the error instead of looping forever.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100