Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

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.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
c
Domain
backend

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.

Description

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

Dominant language
C
Stars
40.4k
Forks
8.2k
Avg merge
2d 12h
Merged PRs (30d)
112

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.

More from php/php-src

All issues in php/php-src

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.