Skip to content
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

vsnprintf return -1 with any buffer size inside separated thread #879

Closed
formatCvt opened this issue Dec 23, 2018 · 6 comments
Closed

vsnprintf return -1 with any buffer size inside separated thread #879

formatCvt opened this issue Dec 23, 2018 · 6 comments
Assignees
Labels

Comments

@formatCvt
Copy link

formatCvt commented Dec 23, 2018

Description

On some Android devices vsprintf return -1 with any buffer size inside separated thread for non-english languages.

Steps to reproduce:
  1. Take any format function (i've tried many). For example this one https://github.com/cocos2d/cocos2d-x/blob/cocos2d-x-3.17/cocos/base/ccUTF8.cpp#L43
  2. Call format function in separated thread twice with delay (1-2 sec) with non-english language text.
Example code:
std::thread _thread = std::thread([](){
    std::string test1 = format("Any text here. Language doesn't matter %d", 1);
    // sleep is important. vsnprint stop working (returns -1) after some delay, not immediately
    sleep(2);
    // non-english language is important
    std::string test2 = format("运送%d个乘客!电工、防火员和警察不算", 1);
});
_thread.detach();

Or use this test case https://github.com/formatCvt/android-ndk-vsnprintf-issue

Environment Details

  • NDK Version: staring from r15c/ (with r14b everything is fine)
  • Build system: cmake/ndk-build
  • Host OS: MacOS 10.13.6/Linux Ubuntu 16.04
  • Compiler: clang
  • ABI: armeabi-v7a
  • STL: c++_static
  • NDK API level: 16
  • Device API level: 24, 26
Non-affected devices (tested)
  • Samsung GT-I9082 (Android 4.2.2, API 17)
  • Xiaomi Mi A1 (Android 8.1.0, API 27)
  • DIGMA VOX S501 3G VS5002PG (Android 5.1, API 22)
  • TCL 5065D (Android 5.1.1, API 22)
  • Sony E5303 (Android 6.0 API 23)
  • Google Pixel XL (Android 9, API 28)
  • Google Pixel 3 XL (Android 9, API 28)
Affected devices (tested):
  • Xiaomi Mi PAD 3 (Android 7.0.0, API 24)
Affected devices (according to top devices from crashlytics issue):
  • waiting for new statistic from crashlytics

Screenshots:

screenshot1
screenshot2

@formatCvt formatCvt added the bug label Dec 23, 2018
@formatCvt
Copy link
Author

We've found and fix other bug in our project related to this issue in crashlytics.
Bug with vsnprintf 100% reproduce on xiaomi mi pad 3, but i'm not sure about other devices right now.
We are waiting for new statistic from crashlytics

@formatCvt formatCvt changed the title vsprintf return -1 with any buffer size inside separated thread vsnprintf return -1 with any buffer size inside separated thread Dec 26, 2018
@DanAlbert
Copy link
Member

Based on your report, this is either a bug with that specific device or perhaps with android-24, not the NDK. This worked in older NDK releases because libandroid_support used to includes its own implementation of vsnprintf. That implementation was the source of countless other bugs, so it is no longer used.

Even if we were to bring that back, libandroid_support is not used for 21+ since it by design overrides system behavior and increases the size of your application, which is generally undesirable.

I'd be curious if this affects other android-24 devices or just that one device.

@alexcohn
Copy link

I'd be curious if this affects other android-24 devices or just that one device.

I tried this on a Chinese 7.0 device, same test case passed smoothly.

@DanAlbert
Copy link
Member

Thanks for the verification. Sounds like this tablet has a broken OS.

As noted above, fixing this in the NDK would increase the size of every NDK app on every device, so we won't be fixing this in the NDK. If you want to work around this in your application, in the same way you did on previous NDKs, you could bundle the implementation from the older NDK. Note that it has other bugs though (which will affect all devices), so that may not be what you want.

@formatCvt
Copy link
Author

formatCvt commented Jan 23, 2019

According to latest statistics from crashlytics affected devices:

  • Xiaomi Mi PAD 3 (Android 7.0.0, API 24)
  • TCT (Alcatel) Alcatel 1X (U5A_PLUS_4G), Android 8.1
  • Xiaomi Redmi 6A (cactus), Android 8.1
  • Xiaomi Redmi 6 (cereus), Android 8.1
  • Huawei Honor 7A (HWDUA-M), Android 8.1

I agree, this list is too short to be fixed in the NDK
We are switched to fmtlib and bug with string formating is gone.

@enh enh reopened this Jan 25, 2019
@enh enh self-assigned this Jan 25, 2019
@enh
Copy link
Contributor

enh commented Jan 25, 2019

actually, although this isn't a NDK issue, i will add a CTS test for this...

@DanAlbert DanAlbert assigned enh-google and unassigned enh Sep 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants