diff --git a/ext/standard/html.c b/ext/standard/html.c
index 194c532a97a..8ea7d9af2ca 100644
--- a/ext/standard/html.c
+++ b/ext/standard/html.c
@@ -533,6 +533,10 @@ inline static unsigned short get_next_char(enum entity_charset charset,
do {
if (this_char < 0x80) {
more = 0;
+ if(stat) {
+ /* we didn't finish the UTF sequence correctly */
+ *status = FAILURE;
+ }
break;
} else if (this_char < 0xc0) {
switch (stat) {