[Mingw-w64-public] std::regex freezes in Japanese locale

Liu Hao lh_mouse@126.com
Sun Jan 24 08:10:24 GMT 2021


在 2021-01-24 02:05, Hannes Domani via Mingw-w64-public 写道:
> Am Samstag, 23. Januar 2021, 16:46:18 MEZ hat Jeroen Ooms <jeroen@berkeley.edu> Folgendes geschrieben:
> 
>> A user of the R programming language has reported that std::regex
>> causes a hang for certain regular expressions when running in Japanese
>> locale. I was able to reproduce this both with our production
>> toolchain (mingw-w64 v5 + gcc 8) as well as the latest msys2
>> toolchains.
>>
>> Is this a bug in mingw-w64 or elsewhere? Below a minimal example:
>>
>> #include <regex>
>> int main() {
>>     setlocale(LC_ALL, "Japanese");
>>     std::regex reg("[0-9]");
>>     return 0;
>> }
> 
> I can reproduce this as well, it took 108 seconds to finish here.
> 
> Deep in regex is this function:
> std::__detail::_BracketMatcher<std::__cxx11::regex_traits<char>, false, false>::_M_make_cache(std::integral_constant<bool, true>)
> 
> This caches transformed values of the unicode values 0-255 to the current
> locale, with strxfrm_l [1].
> This fails for a lot of them for japanese, and as documented, strxfrm_l
> returns INT_MAX in this case.
> But std::collate::do_transform does not handle any error case, it uses all
> return values as the length of the transformed string.
> And then it creates a copy of this 2GB string, which takes a lot of time,
> around ~1s for each failing character.
> 
> It think this should be reported to gcc (libstdc++).
> 
> 
> [1] https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/strxfrm-wcsxfrm-strxfrm-l-wcsxfrm-l?view=msvc-160
> 
> 

Add CC libstdc++ and jwakely.

Despite Microsoft docs, the standard `_?(str|wcs)xfrm(_l)?` functions don't have return values to 
indicate errors. This issue seems to be caused by invalid MBCSs passed to `_strxfrm_l`, which should 
be avoided.




-- 
Best regards,
LH_Mouse

-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20210124/43cb24bb/attachment.sig>


More information about the Libstdc++ mailing list