This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] Error out if __libcpp_mbsrtowcs_l fails to convert anything in __time_get_storage
ClosedPublic

Authored by mstorsjo on Oct 29 2019, 2:33 AM.

Details

Summary

If __libcpp_mbsrtowcs_l outputs zero wchar_t's for week days or month names (due to errors in the locale function setup), these are matched all the time in __time_get_storage::__analyze, ending up in an infinite loop, allocating more memory until killed.

Diff Detail

Event Timeline

mstorsjo created this revision.Oct 29 2019, 2:33 AM
ldionne requested changes to this revision.Nov 2 2020, 2:28 PM
ldionne added a reviewer: Restricted Project.

Can we add a test for this alongside the fix?

This revision now requires changes to proceed.Nov 2 2020, 2:28 PM

To test the issue itself, you'd need a platform with broken locale functions, and the issue is triggered by a number of the existing testcases.

The locale functions were broken in such a way on windows, triggering this issue, prior to D69505 - and that patch fixed around 11 of the previously broken tests.

Before the patch that fixed the windows issue, the symptom of the problem was libc++ getting stuck in infinite loops; with this patch it would error out much more cleanly, which would have made it a bit easier to locate the root cause behind D69505.

So this patch doesn't fix any issue, it just changes a bad failure case (infinite loop) into a more manageable one (throwing an error).

ldionne accepted this revision.Nov 3 2020, 4:39 AM
This revision is now accepted and ready to land.Nov 3 2020, 4:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 3 2020, 7:15 AM