Skip to content

Commit 9cfd8f4

Browse files
committed
Don't fall back to vtbl_pass if no matching vtbl found
If we don't know how to convert between two encodings, make sure we error instead of ignoring the issue. Explicitly use vtbl_pass if we are round-tripping wchar->wchar or 8bit->8bit. Fingers crossed that nothing else relies on the vtbl_pass fallback...
1 parent d7e96c1 commit 9cfd8f4

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

ext/mbstring/libmbfl/mbfl/mbfilter.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ mbfl_buffer_converter_new(
147147

148148
/* create convert filter */
149149
convd->filter1 = NULL;
150-
convd->filter2 = NULL;
150+
convd->filter2 = NULL;
151151
if (mbfl_convert_filter_get_vtbl(convd->from, convd->to) != NULL) {
152152
convd->filter1 = mbfl_convert_filter_new(convd->from, convd->to, mbfl_memory_device_output, NULL, &convd->device);
153153
} else {
@@ -164,6 +164,7 @@ convd->filter2 = NULL;
164164
}
165165
}
166166
if (convd->filter1 == NULL) {
167+
mbfl_free(convd);
167168
return NULL;
168169
}
169170

@@ -2399,7 +2400,7 @@ mime_header_decoder_new(const mbfl_encoding *outcode)
23992400
mbfl_memory_device_init(&pd->tmpdev, 0, 0);
24002401
pd->cspos = 0;
24012402
pd->status = 0;
2402-
pd->encoding = &mbfl_encoding_pass;
2403+
pd->encoding = &mbfl_encoding_8bit;
24032404
pd->incode = &mbfl_encoding_ascii;
24042405
pd->outcode = outcode;
24052406
/* charset convert filter */

ext/mbstring/libmbfl/mbfl/mbfl_convert.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,8 @@ mbfl_convert_filter_new(
171171
const struct mbfl_convert_vtbl *vtbl;
172172

173173
vtbl = mbfl_convert_filter_get_vtbl(from, to);
174-
175174
if (vtbl == NULL) {
176-
vtbl = &vtbl_pass;
175+
return NULL;
177176
}
178177

179178
/* allocate */
@@ -454,6 +453,10 @@ const struct mbfl_convert_vtbl * mbfl_convert_filter_get_vtbl(
454453
to = &mbfl_encoding_8bit;
455454
}
456455

456+
if (to == from && (to == &mbfl_encoding_wchar || to == &mbfl_encoding_8bit)) {
457+
return &vtbl_pass;
458+
}
459+
457460
if (to->no_encoding == mbfl_no_encoding_wchar) {
458461
return from->input_filter;
459462
} else if (from->no_encoding == mbfl_no_encoding_wchar) {

0 commit comments

Comments
 (0)