Repository navigation
mod_proxy_fcgi, mod_brotli: Fix NULL deref when a FastCGI backend sends data after an early empty FCGI_STDOUT record - #1008
Open
arturobernalg wants to merge 2 commits into
Conversation
arturobernalg
force-pushed
the
fix/bz66168-brotli-proxy-fcgi-eos
branch
2 times, most recently
from
November 18, 2026 15:00
7735483 to
228724e
Compare
data after its own premature, stream-ending empty FCGI_STDOUT record. Some backends (PHP-FPM hitting PHP bug #72185, for one) emit a zero-length FCGI_STDOUT record too early and keep sending STDOUT data afterwards. mod_proxy_fcgi treated the empty record as end of stream, sent an EOS bucket down the filter chain, but kept forwarding the backend's later STDOUT data as if it were new content. A filter that tears down internal state on EOS and never removes itself from the chain -- mod_brotli's encoder, in this case -- gets invoked again with that stale state and crashes. Discard FastCGI STDOUT data received after the stream-ending record instead of forwarding it, and have mod_brotli remove itself from the output filter chain once it has seen EOS so it can never be invoked again for the same request regardless of the cause. PR: https://bz.apache.org/bugzilla/show_bug.cgi?id=66168
arturobernalg
force-pushed
the
fix/bz66168-brotli-proxy-fcgi-eos
branch
from
November 18, 2026 18:29
228724e to
10dfd60
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Some FastCGI backends (PHP-FPM hitting PHP bug #72185, for one) emit a zero-length FCGI_STDOUT record too early and then keep sending STDOUT data afterwards. mod_proxy_fcgi treated the empty record as end of stream and sent an EOS bucket down the output filter chain, but kept reading and forwarding the backend's later STDOUT data as if it were new content.
A filter that tears down its internal state on EOS and never removes itself from the chain -- mod_brotli's encoder, in this case -- gets invoked again with that stale (destroyed) state and crashes with a NULL pointer dereference, killing the worker process and all other connections it was handling.
This fixes it at both ends: mod_proxy_fcgi now discards FastCGI STDOUT data received after the stream-ending empty record instead of forwarding it (logging a one-time warning, APLOGNO 10682), and mod_brotli now removes itself from the output filter chain as soon as it sees EOS, matching the defensive pattern mod_deflate already uses, so it can never be invoked again for the same request regardless of the cause.
Reproduced with a minimal FastCGI responder (no PHP needed) that sends the same malformed record sequence PHP-FPM does, confirmed the crash on an unpatched build (AH00051, exit signal Segmentation fault), and added a pytest regression test (test/modules/proxy/test_08_fcgi_eos.py) that fails the same way without the fix and passes with it.
BZ: https://bz.apache.org/bugzilla/show_bug.cgi?id=66168
[x] This PR does not report or address a security vulnerability (see SECURITY.md and https://www.apache.org/security/#reporting-a-vulnerability).
[x] Code follows the httpd style guide.
[x] New log messages (level debug or higher) use an empty APLOGNO() tag.
[x] If the change is user-visible, a changes-entries/*.txt file is included.
[x] Test cases based on pyhttpd are included.