Skip to content

Commit bce9555

Browse files
Proper fix for mbstring
1 parent 0932cef commit bce9555

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

ext/mbstring/mbstring.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,10 +1584,22 @@ PHP_FUNCTION(mb_output_handler)
15841584
if (SG(sapi_headers).send_default_content_type || free_mimetype) {
15851585
const char *charset = encoding->mime_name;
15861586
if (charset) {
1587-
char *p;
1588-
size_t len = spprintf(&p, 0, "Content-Type: %s; charset=%s", mimetype, charset);
1589-
if (sapi_add_header(p, len, 0) != FAILURE) {
1590-
SG(sapi_headers).send_default_content_type = 0;
1587+
/* Don't try to add a header if we are in an output handler;
1588+
* we aren't supposed to directly access the output globals
1589+
* from outside of main/output.c, so just try to get the flags
1590+
* for the currently running handler, will only succeed if
1591+
* there is a handler running. */
1592+
int unused;
1593+
bool in_handler = php_output_handler_hook(
1594+
PHP_OUTPUT_HANDLER_HOOK_GET_FLAGS,
1595+
&unused
1596+
) == SUCCESS;
1597+
if (!in_handler) {
1598+
char *p;
1599+
size_t len = spprintf(&p, 0, "Content-Type: %s; charset=%s", mimetype, charset);
1600+
if (sapi_add_header(p, len, 0) != FAILURE) {
1601+
SG(sapi_headers).send_default_content_type = 0;
1602+
}
15911603
}
15921604
}
15931605

0 commit comments

Comments
 (0)