@@ -5853,6 +5853,8 @@ static void transfer_encode_mime_bytes(mb_convert_buf *tmpbuf, mb_convert_buf *o
5853
5853
MB_CONVERT_BUF_STORE (outbuf , out , limit );
5854
5854
}
5855
5855
5856
+ #define MBSTRING_HEADER_ENC_WCHAR_BUFSIZE 90
5857
+
5856
5858
static 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 )
5857
5859
{
5858
5860
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
5883
5885
unsigned int state = 0 ;
5884
5886
/* wchar_buf should be big enough that when it is full, we definitely have enough
5885
5887
* 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 ];
5888
5889
uint32_t * p , * e ;
5889
5890
/* What part of wchar_buf is filled with still-unprocessed data which should not
5890
5891
* be overwritten? */
@@ -5895,7 +5896,7 @@ static zend_string* mb_mime_header_encode(zend_string *input, const mbfl_encodin
5895
5896
* spaces), just pass it through unchanged */
5896
5897
bool checking_leading_spaces = true;
5897
5898
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 );
5899
5900
p = wchar_buf ;
5900
5901
e = wchar_buf + out_len ;
5901
5902
@@ -5929,9 +5930,9 @@ no_passthrough: ;
5929
5930
* do so all the way to the end of the string */
5930
5931
while (in_len ) {
5931
5932
/* 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 );
5935
5936
p = wchar_buf ;
5936
5937
e = wchar_buf + offset + out_len ;
5937
5938
/* ASCII output is broken into space-delimited 'words'
@@ -6039,16 +6040,16 @@ mime_encoding_needed: ;
6039
6040
/* Do we need to refill wchar_buf to make sure we don't run out of wchars
6040
6041
* in the middle of a line? */
6041
6042
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 ) {
6043
6044
goto start_new_line ;
6044
6045
}
6045
6046
memmove (wchar_buf , p , offset * sizeof (uint32_t ));
6046
6047
6047
6048
while (true) {
6048
6049
refill_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 );
6052
6053
p = wchar_buf ;
6053
6054
e = wchar_buf + offset + out_len ;
6054
6055
@@ -6129,7 +6130,7 @@ start_new_line: ;
6129
6130
buf .out = mb_convert_buf_add (buf .out , ' ' );
6130
6131
line_start = mb_convert_buf_len (& buf );
6131
6132
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 )) {
6133
6134
/* Copy any remaining wchars to beginning of buffer and refill
6134
6135
* the rest of the buffer */
6135
6136
memmove (wchar_buf , p , offset * sizeof (uint32_t ));
0 commit comments