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

CFStringRef#stringValue fails if string consists entirely of 3-byte UTF characters #1611

Closed
caifenglin opened this issue Apr 21, 2021 · 2 comments · Fixed by #1701
Closed
Labels
confirmed bug Confirmed bugs. Highest priority to fix. external dependency Bug/error in another project OSHI depends on fixed Bug fixed, if issue is open needs user testing

Comments

@caifenglin
Copy link

version:<oshi.version>5.7.1</oshi.version>
java.lang.IllegalArgumentException: CFString conversion fails or the provided buffer is too small.
at com.sun.jna.platform.mac.CoreFoundation$CFStringRef.stringValue(CoreFoundation.java:502)

@dbwiddis
Copy link
Member

This error occurs in JNA. I need more context to determine what the problem may be.

The code is here:

https://github.com/java-native-access/jna/blob/master/contrib/platform/src/com/sun/jna/platform/mac/CoreFoundation.java#L490-L502

It gets the character length of the string using CFStringGetLength();
It gets the max length in bytes that could possibly fit using UTF8 encoding;
It allocates a buffer of that size and fetches the string.

Possible problems:

  • The data is in a format other than UTF8 (?)
  • The length of the string changes during method execution

@dbwiddis dbwiddis added the external dependency Bug/error in another project OSHI depends on label Apr 21, 2021
@dbwiddis
Copy link
Member

Looks like this can happen if the string consists completely of 3-byte unicode characters. I'll fix this upstream java-native-access/jna#1342

@dbwiddis dbwiddis added the confirmed bug Confirmed bugs. Highest priority to fix. label Apr 21, 2021
@dbwiddis dbwiddis changed the title Error reporting in Apple system CFStringRef fails if string consists entirely of 3-byte UTF characters Apr 22, 2021
@dbwiddis dbwiddis changed the title CFStringRef fails if string consists entirely of 3-byte UTF characters CFStringRef#stringValue fails if string consists entirely of 3-byte UTF characters Apr 22, 2021
@dbwiddis dbwiddis added the fixed Bug fixed, if issue is open needs user testing label May 4, 2021
@dbwiddis dbwiddis mentioned this issue Aug 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed bug Confirmed bugs. Highest priority to fix. external dependency Bug/error in another project OSHI depends on fixed Bug fixed, if issue is open needs user testing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants