Skip to content

ICU-23120 Fix malloc request larger than PTRDIFF_MAX bytes #3496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

SoapGentoo
Copy link

@SoapGentoo SoapGentoo commented May 16, 2025

    work/icu/source/test/intltest/ustrtest.cpp: In member function ‘void UnicodeStringTest::TestLargeMemory()’:
    work/icu/source/test/intltest/ustrtest.cpp:2360:37: error: size ‘4294967286’ of array exceeds maximum object size ‘2147483647’
     2360 |     char16_t *buf = new char16_t[len];
          |                                     ^

Checklist

  • Required: Issue filed: ICU-23120
  • Required: The PR title must be prefixed with a JIRA Issue number. Example: "ICU-1234 Fix xyz"
  • Required: Each commit message must be prefixed with a JIRA Issue number. Example: "ICU-1234 Fix xyz"
  • Issue accepted (done by Technical Committee after discussion)
  • Tests included, if applicable
  • API docs and/or User Guide docs changed or added, if applicable

* glibc does not allow allocations that exceed PTRDIFF_MAX bytes:
  https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=9bf8e29ca136094f73f69f725f15c51facc97206
* Without this, we get compile failures on 32-bit platforms:

    work/icu/source/test/intltest/ustrtest.cpp: In member function ‘void UnicodeStringTest::TestLargeMemory()’:
    work/icu/source/test/intltest/ustrtest.cpp:2360:37: error: size ‘4294967286’ of array exceeds maximum object size ‘2147483647’
     2360 |     char16_t *buf = new char16_t[len];
          |                                     ^
@CLAassistant
Copy link

CLAassistant commented May 16, 2025

CLA assistant check
All committers have signed the CLA.

@@ -2356,7 +2356,7 @@ void UnicodeStringTest::TestLargeMemory() {
#if U_PLATFORM_IS_LINUX_BASED || U_PLATFORM_IS_DARWIN_BASED
if(quick) { return; }
IcuTestErrorCode status(*this, "TestLargeMemory");
constexpr uint32_t len = 2147483643;
constexpr uint32_t len = (PTRDIFF_MAX - 10) / sizeof(char16_t);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect that this change would leave this test non-functional on 64 bit platforms, which is the only place it can work in the first place. UnicodeString keeps its length as a 32 bit value. Probably the intent of the test was to make sure that UnicodeString doesn't fail in some weird way with a length near the 32 bit max limit.

PTRDIFF_MAX on 64 bit platforms won't give the right 32 bit max UnicodeString length value.

Allocating the requested sized buffer on a 32 bit platform is impossible - it's too big to fit in the available address space.

Maybe just add a condition to the existing platform #if checks to bypass the test on 32 bit platforms.

@markusicu markusicu self-assigned this May 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants