Skip to content

Commit d617fca

Browse files
committed
Fix legacy text conversion filter for 'HTML-ENTITIES'
Because this routine used a signed char buffer to hold the bytes in a (possible) HTML entity, any bytes with the MSB set would be sign-extended when converting to int; for example, 0x86 would become 0xFFFFFF86 (or -121). Codepoints with huge values, like 0xFFFFFF86, are not valid and if any were passed to the output filter, it would treat them as errors and emit error markers.
1 parent d9269be commit d617fca

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

ext/mbstring/libmbfl/filters/mbfilter_htmlent.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ int mbfl_filt_conv_html_dec(int c, mbfl_convert_filter *filter)
180180
int pos;
181181
unsigned int ent = 0;
182182
mbfl_html_entity_entry *entity;
183-
char *buffer = (char*)filter->opaque;
183+
unsigned char *buffer = (unsigned char*)filter->opaque;
184184

185185
if (!filter->status) {
186186
if (c == '&' ) {
@@ -196,7 +196,7 @@ int mbfl_filt_conv_html_dec(int c, mbfl_convert_filter *filter)
196196
if (filter->status > 3) {
197197
/* numeric entity */
198198
for (pos=3; pos<filter->status; pos++) {
199-
int v = buffer[pos];
199+
int v = buffer[pos];
200200
if (v >= '0' && v <= '9') {
201201
v = v - '0';
202202
} else if (v >= 'A' && v <= 'F') {
@@ -242,13 +242,12 @@ int mbfl_filt_conv_html_dec(int c, mbfl_convert_filter *filter)
242242
CK((*filter->output_function)(c, filter->data));
243243
}
244244
filter->status = 0;
245-
/*php_error_docref("ref.mbstring", E_NOTICE, "mbstring decoded '%s'=%d", buffer, ent);*/
246245
} else {
247246
/* named entity */
248247
buffer[filter->status] = 0;
249248
entity = (mbfl_html_entity_entry *)mbfl_html_entity_list;
250249
while (entity->name) {
251-
if (!strcmp(buffer+1, entity->name)) {
250+
if (!strcmp((const char*)buffer+1, entity->name)) {
252251
ent = entity->code;
253252
break;
254253
}

0 commit comments

Comments
 (0)