Skip to content

Instantly share code, notes, and snippets.

@igorsnunes
Last active September 24, 2015 16:39
Show Gist options
  • Save igorsnunes/f25023b284404d76acb9 to your computer and use it in GitHub Desktop.
Save igorsnunes/f25023b284404d76acb9 to your computer and use it in GitHub Desktop.
Different behavior between x86_64 and ppc64le in overflow in locale_get_display_name
When running the attached example in x86_64 and powerpc64le, different results are presented.
The attached file calls the function getDisplayName imported from libicu.
It is expected that in both architectures the program crashes in a core dump as pointed in [1] and
[2]. But in powerpc64le the last printed character is 247 and in x86_64 it is 255, i.e. in x86_64
the overflow happens 8 bytes ahead of ppc64le.
In order to compile the below code, the following command line is used:
g++ test-libicu.cpp -o a.out -std=c++11 -licuuc
[1] https://github.com/facebook/hhvm/blob/master/hphp/runtime/ext/icu/ext_icu_locale.cpp#L223
[2] https://bugs.php.net/bug.php?id=67397
#include <unicode/ures.h>
#include <unicode/uloc.h>
#include <algorithm>
#include <utility>
#include <vector>
int main ()
{
for (unsigned int i = 0; i < 260; i++)
{
printf("Locale size: %d\n", i);
std::string locale_name("");
for (unsigned int j = 0; j < i; j++)
{
locale_name.append("*");
}
std::string disp_locale("a");
UErrorCode error = U_ZERO_ERROR;
icu::UnicodeString buf;
auto ubuf = buf.getBuffer(64);
int32_t (*ulocfunc)(const char *loc, const char *dloc,
UChar *dest, int32_t destcap, UErrorCode *err);
ulocfunc = uloc_getDisplayName;
int32_t len = ulocfunc(locale_name.c_str(), disp_locale.c_str(), ubuf, buf.getCapacity(), &error);
}
return 0;
}
@leitao
Copy link

leitao commented Sep 23, 2015

The final problem seems to be on the following line:
318 if (!uprv_strncmp(tableKey, "Languages", 9) && uprv_strtol(itemKey, NULL, 10)) {

@igorsnunes
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment