Fixed bug #74484 MessageFormatter::formatMessage memory corruption

with 11+ named placeholder
This commit is contained in:
Anatol Belski 2018-08-09 22:07:24 +02:00
parent 935625f1b8
commit 45a05f3841
2 changed files with 52 additions and 0 deletions

View file

@ -27,6 +27,7 @@
#include <unicode/timezone.h>
#include <unicode/datefmt.h>
#include <unicode/calendar.h>
#include <unicode/strenum.h>
#include <vector>
@ -333,6 +334,24 @@ static void umsg_set_timezone(MessageFormatter_object *mfo,
return; /* already done */
}
/* There is a bug in ICU which prevents MessageFormatter::getFormats()
to handle more than 10 formats correctly. The enumerator could be
used to walk through the present formatters using getFormat(), which
however seems to provide just a readonly access. This workaround
prevents crash when there are > 10 formats but doesn't set any error.
As a result, only DateFormatters with > 10 subformats are affected.
This workaround should be ifdef'd out, when the bug has been fixed
in ICU. */
icu::StringEnumeration* fnames = mf->getFormatNames(err.code);
if (!fnames || U_FAILURE(err.code)) {
return;
}
count = fnames->count(err.code);
delete fnames;
if (count > 10) {
return;
}
formats = mf->getFormats(count);
if (formats == NULL) {