Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix substitution of invalid UTF8 sequences in htmlspecialchars. #2680

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
$str = "a\xebcd";
echo bin2hex(htmlspecialchars($str, ENT_SUBSTITUTE))."\n";
echo bin2hex(htmlspecialchars(htmlspecialchars($str, ENT_SUBSTITUTE), ENT_SUBSTITUTE))."\n";
echo bin2hex(htmlspecialchars("b\xeddd", ENT_SUBSTITUTE))."\n";
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
61efbfbd6364
61efbfbd6364
62efbfbd6464
10 changes: 4 additions & 6 deletions hphp/zend/zend-html.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,9 +725,7 @@ char *string_html_encode(const char *input, int &len,
entity[2] = '\0';
} else if (c < 0xf0) {
UTF8_ERROR_IF(avail < 3);
for (int i = 1; i < 3; ++i) {
UTF8_ERROR_IF(!utf8_trail(*(p + i)));
}
UTF8_ERROR_IF(!utf8_trail(*(p + 1)) || !utf8_trail(*(p + 2)));

uint32_t tc = ((c & 0x0f) << 12) |
((*(p+1) & 0x3f) << 6) |
Expand All @@ -742,9 +740,9 @@ char *string_html_encode(const char *input, int &len,
entity[3] = '\0';
} else if (c < 0xf5) {
UTF8_ERROR_IF(avail < 4);
for (int i = 1; i < 4; ++i) {
UTF8_ERROR_IF(!utf8_trail(*(p + i)));
}
UTF8_ERROR_IF(!utf8_trail(*(p + 1)));
UTF8_ERROR_IF(!utf8_trail(*(p + 2)));
UTF8_ERROR_IF(!utf8_trail(*(p + 3)));

uint32_t tc = ((c & 0x07) << 18) |
((*(p+1) & 0x3f) << 12) |
Expand Down