Last active
September 24, 2015 16:39
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
reported in http://bugs.icu-project.org/trac/ticket/11936