@@ -5853,6 +5853,8 @@ static void transfer_encode_mime_bytes(mb_convert_buf *tmpbuf, mb_convert_buf *o
58535853 MB_CONVERT_BUF_STORE (outbuf , out , limit );
58545854}
58555855
5856+ #define MBSTRING_HEADER_ENC_WCHAR_BUFSIZE 90
5857+
58565858static zend_string * mb_mime_header_encode (zend_string * input , const mbfl_encoding * incode , const mbfl_encoding * outcode , bool base64 , char * linefeed , size_t linefeed_len , zend_long indent )
58575859{
58585860 unsigned char * in = (unsigned char * )ZSTR_VAL (input );
@@ -5883,8 +5885,7 @@ static zend_string* mb_mime_header_encode(zend_string *input, const mbfl_encodin
58835885 unsigned int state = 0 ;
58845886 /* wchar_buf should be big enough that when it is full, we definitely have enough
58855887 * wchars to fill an entire line of output */
5886- const size_t wchar_buf_len = 90 ;
5887- uint32_t wchar_buf [wchar_buf_len ];
5888+ uint32_t wchar_buf [MBSTRING_HEADER_ENC_WCHAR_BUFSIZE ];
58885889 uint32_t * p , * e ;
58895890 /* What part of wchar_buf is filled with still-unprocessed data which should not
58905891 * be overwritten? */
@@ -5895,7 +5896,7 @@ static zend_string* mb_mime_header_encode(zend_string *input, const mbfl_encodin
58955896 * spaces), just pass it through unchanged */
58965897 bool checking_leading_spaces = true;
58975898 while (in_len ) {
5898- size_t out_len = incode -> to_wchar (& in , & in_len , wchar_buf , wchar_buf_len , & state );
5899+ size_t out_len = incode -> to_wchar (& in , & in_len , wchar_buf , MBSTRING_HEADER_ENC_WCHAR_BUFSIZE , & state );
58995900 p = wchar_buf ;
59005901 e = wchar_buf + out_len ;
59015902
@@ -5929,9 +5930,9 @@ no_passthrough: ;
59295930 * do so all the way to the end of the string */
59305931 while (in_len ) {
59315932 /* Decode part of the input string, refill wchar_buf */
5932- ZEND_ASSERT (offset + MBSTRING_MIN_WCHAR_BUFSIZE <= wchar_buf_len );
5933- size_t out_len = incode -> to_wchar (& in , & in_len , wchar_buf + offset , wchar_buf_len - offset , & state );
5934- ZEND_ASSERT (out_len <= wchar_buf_len - offset );
5933+ ZEND_ASSERT (offset + MBSTRING_MIN_WCHAR_BUFSIZE <= MBSTRING_HEADER_ENC_WCHAR_BUFSIZE );
5934+ size_t out_len = incode -> to_wchar (& in , & in_len , wchar_buf + offset , MBSTRING_HEADER_ENC_WCHAR_BUFSIZE - offset , & state );
5935+ ZEND_ASSERT (out_len <= MBSTRING_HEADER_ENC_WCHAR_BUFSIZE - offset );
59355936 p = wchar_buf ;
59365937 e = wchar_buf + offset + out_len ;
59375938 /* ASCII output is broken into space-delimited 'words'
@@ -6039,16 +6040,16 @@ mime_encoding_needed: ;
60396040 /* Do we need to refill wchar_buf to make sure we don't run out of wchars
60406041 * in the middle of a line? */
60416042 offset = e - p ;
6042- if (wchar_buf_len - offset < MBSTRING_MIN_WCHAR_BUFSIZE ) {
6043+ if (MBSTRING_HEADER_ENC_WCHAR_BUFSIZE - offset < MBSTRING_MIN_WCHAR_BUFSIZE ) {
60436044 goto start_new_line ;
60446045 }
60456046 memmove (wchar_buf , p , offset * sizeof (uint32_t ));
60466047
60476048 while (true) {
60486049refill_wchar_buf : ;
6049- ZEND_ASSERT (offset + MBSTRING_MIN_WCHAR_BUFSIZE <= wchar_buf_len );
6050- size_t out_len = incode -> to_wchar (& in , & in_len , wchar_buf + offset , wchar_buf_len - offset , & state );
6051- ZEND_ASSERT (out_len <= wchar_buf_len - offset );
6050+ ZEND_ASSERT (offset + MBSTRING_MIN_WCHAR_BUFSIZE <= MBSTRING_HEADER_ENC_WCHAR_BUFSIZE );
6051+ size_t out_len = incode -> to_wchar (& in , & in_len , wchar_buf + offset , MBSTRING_HEADER_ENC_WCHAR_BUFSIZE - offset , & state );
6052+ ZEND_ASSERT (out_len <= MBSTRING_HEADER_ENC_WCHAR_BUFSIZE - offset );
60526053 p = wchar_buf ;
60536054 e = wchar_buf + offset + out_len ;
60546055
@@ -6129,7 +6130,7 @@ start_new_line: ;
61296130 buf .out = mb_convert_buf_add (buf .out , ' ' );
61306131 line_start = mb_convert_buf_len (& buf );
61316132 offset = e - p ;
6132- if (in_len && (wchar_buf_len - offset >= MBSTRING_MIN_WCHAR_BUFSIZE )) {
6133+ if (in_len && (MBSTRING_HEADER_ENC_WCHAR_BUFSIZE - offset >= MBSTRING_MIN_WCHAR_BUFSIZE )) {
61336134 /* Copy any remaining wchars to beginning of buffer and refill
61346135 * the rest of the buffer */
61356136 memmove (wchar_buf , p , offset * sizeof (uint32_t ));
0 commit comments