diff --git a/sakura_core/charset/CESI.cpp b/sakura_core/charset/CESI.cpp index fb916497b7..cb046b9d88 100644 --- a/sakura_core/charset/CESI.cpp +++ b/sakura_core/charset/CESI.cpp @@ -981,8 +981,12 @@ ECodeType CESI::AutoDetectByXML( const char* pBuf, int nSize ) } quoteChar = pBuf[i]; i++; - std::string sBuf = pBuf; - return MatchEncoding( pBuf + i, sBuf.find_first_of( quoteChar, i ) - i ); + std::string_view sBuf( pBuf, nSize ); + auto nLen = sBuf.find_first_of( quoteChar, i ); + if( nLen == std::string_view::npos ){ + break; + } + return MatchEncoding( pBuf + i, nLen - i ); }else{ if( pBuf[i] == '<' || pBuf[i] == '>' ){ break;