php / php/php-src

php_embed_ub_write does not return on error

Open Beginner friendly
#23,423 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Status: Needs Triage
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.