We're updating the issue view to help you get more done. 

OOM: use a stack allocated Resource Bundle in ucal_getTZDataVersion/getTZDataVersion (ICU4C)


The public API functions ucal_getTZDataVersion (C) and getTZDataVersion (C++) both call into the function initTZDataVersion, which calls into ures_openDirect.

However, ures_openDirect will attempt to allocate memory for a number of things, one of which is the Resource Bundle. This can possibly fail (due to OOM), leading to the APIs returning a pointer to null.

If a stack allocated Resource Bundle could be used instead, then there would be one less thing that needs heap allocation in this code path.

Unfortunately, the internal function ures_openDirect does not take a Resource Bundle parameter, which means that it will always allocate.

We can add a similar internal API ures_openDirectFillIn which does take a Resource Bundle, and fills it in instead.
(This is similar to the ures_open and ures_openFillIn functions – one of which allocates and the other fills in an existing one).

The proposed internal API would look like this (in the file uresbund.cpp):

1 2 3 4 5 6 7 8 9 10 11 12 /** * Same as ures_openDirect(), but uses the fill-in parameter and * does not allocate a new bundle. */ U_INTERNAL void U_EXPORT2 ures_openDirectFillIn(UResourceBundle *fillIn, const char* path, const char* localeID, UErrorCode* status) { if(U_SUCCESS(*status) && fillIn == NULL) { *status = U_ILLEGAL_ARGUMENT_ERROR; return; } ures_openWithType(fillIn, path, localeID, URES_OPEN_DIRECT, status); }




Jeff Genovy


Jeff Genovy



Markus Scherer


Fix versions