Skip to content

Commit 4b37033

Browse files
committed
Ensure that Base64 output always wraps lines in the same manner as legacy implementation
The legacy Base64 conversion code in mbstring automatically wrapped the output to 72 columns, and the new code imitates this behavior. Frankly, I'm not sure if this is a good idea or not (people could easily manually wrap it if they want to), but have stuck with this behavior for backwards compatibility. However, fuzzing revealed one case where we were not wrapping to 72 columns; if the input string is not a multiple of 3 characters, meaning that the output must be padded, and the point where we must add the final (padded) output happens to be just beyond 72 columns.
1 parent c6bd085 commit 4b37033

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

ext/mbstring/libmbfl/filters/mbfilter_base64.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,10 @@ static void mb_wchar_to_base64(uint32_t *in, size_t len, mb_convert_buf *buf, bo
337337
}
338338

339339
if (end && bits) {
340+
if (chars_output > 72) {
341+
out = mb_convert_buf_add2(out, '\r', '\n');
342+
chars_output = 0;
343+
}
340344
if (bits == 8) {
341345
out = mb_convert_buf_add4(out, mbfl_base64_table[(cache >> 2) & 0x3F], mbfl_base64_table[(cache & 0x3) << 4], '=', '=');
342346
} else {

0 commit comments

Comments
 (0)