-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Crash at assertion on message length in dispatch.c #1452
Comments
I was able to reproduce this (JNA 5.12.1, openjdk 18.0.2, macOS 12.5, x86_64) with the following alteration to what used to be the string "IOKit": IOKit INSTANCE = Native.load(String.join("JNA", Collections.nCopies(40, "JNA")), IOKit.class); That's a 123-character filename, plus Turns out only 17x3 = 51 character filename plus extension plus 5 different search paths and all their characters and the "(no such file)" string gets to 993 characters total. While the 128-character filename limit suggests one maximum, the path can be 1024 bytes on macOS which would allow for over a hundred directories, so it's not a useful maximum. I'm not sure what the max limit should be, but 1024 is probably too low. |
Instead of increasing the buffer, just dropping the assert (or compiling with |
A list of all the paths it looked in, which actually is useful for debugging, not unlike what JNA does on the Java side. Here's what a misnamed library currently prints:
|
I think a truncated message with no crash would be sufficient. |
I pushed a first possible fix version to #1456. Instead of relying on a static message size, the required buffer is allocated when generated and then freed after exception is thrown. |
I took a shot at this but it looks like the way our build works makes it difficult to test this on the real thing without an artifact to point at. But, I grafted the right jnidispatch binary into a separate smaller build and that seemed to work fine. |
Thanks for the fix. This bug can also occur when using JNA in an app that's in app translocation due to the very long paths that can result. |
When can we expect to see this fix in a release? We have implemented a workaround in our project that informs MacOS users they are not running the application from the Applications folder and would like to remove it when this fix is officially released. Thanks in advance! |
I'm looking at the end of year to get a release out: https://groups.google.com/g/jna-users/c/Vag9ydD0voY |
This MR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [net.java.dev.jna:jna](https://github.com/java-native-access/jna) | compile | minor | `5.12.1` -> `5.13.0` | --- ### Release Notes <details> <summary>java-native-access/jna</summary> ### [`v5.13.0`](https://github.com/java-native-access/jna/blob/HEAD/CHANGES.md#Release-5130) [Compare Source](java-native-access/jna@5.12.1...5.13.0) \================ ## Features - [#​1454](java-native-access/jna#1454): Add `c.s.j.p.win32.Psapi.QueryWorkingSetEx` and associated Types - [@​crain-32](https://github.com/Crain-32). - [#​1459](java-native-access/jna#1459): Add `VirtualLock` and `VirtualUnlock` in `c.s.j.p.win32.Kernel32` - [@​matthiasblaesing](https://github.com/matthiasblaesing). - [#​1471](java-native-access/jna#1471): Add `c.s.j.p.win32.Advapi32Util#isCurrentProcessElevated` and associated Types - [@​dbwiddis](https://github.com/dbwiddis). - [#​1474](java-native-access/jna#1474): Add `c.s.j.p.win32.WbemCli#IWbemClassObject.IWbemQualifierSet`, `IWbemServices.GetObject`, `IWbemContext.SetValue` and associated methods - [@​rchateauneu](https://github.com/rchateauneu). - [#​1482](java-native-access/jna#1482): Add multilingual support of `Kernel32Util.formatMessage` - [@​overpathz](https://github.com/overpathz). - [#​1490](java-native-access/jna#1490): Adds support for a custom `SymbolProvider` in `NativeLibrary` & `Library` - [@​soywiz](https://github.com/soywiz). - [#​1491](java-native-access/jna#1491): Update libffi to v3.4.4 - [@​matthiasblaesing](https://github.com/matthiasblaesing). - [#​1487](java-native-access/jna#1487): Add 'uses' information to OSGI metadata in MANIFEST.MF to improve stability of package resolution - [@​sratz](https://github.com/sratz). ## Bug Fixes - [#​1452](java-native-access/jna#1452): Fix memory allocation/handling for error message generation in native library code (`dispatch.c`) - [@​matthiasblaesing](https://github.com/matthiasblaesing). - [#​1460](java-native-access/jna#1460): Fix win32 variant date conversion in DST offest window and with millisecond values - [@​eranl](https://github.com/eranl). - [#​1472](java-native-access/jna#1472): Fix incorrect bitmask in `c.s.j.Pointer#createConstant(int)` - [@​dbwiddis](https://github.com/dbwiddis). - [#​1481](java-native-access/jna#1481): Fix NPE in NativeLibrary when unpacking from classpath is disabled - [@​trespasserw](https://github.com/trespasserw). - [#​1489](java-native-access/jna#1489): Fixes typo in `OpenGL32Util#wglGetProcAddress`, instead of parameter `procName` the hardcoded value `wglEnumGpusNV` was used - [@​soywiz](https://github.com/soywiz). </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever MR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4yNC4wIiwidXBkYXRlZEluVmVyIjoiMzQuMjQuMCJ9-->
We discovered an issue where on upgrading our build machines to macOS 12, tests started to crash with an assertion failure in JNA's
dispatch.c
- presumably the error fromdlerror()
is now longer than JNA's permitted maximum of 1024.On investigation, it seems the error only gets triggered if loading the library fails - the test in particular which triggered this is possible to skip for macOS, but I don't yet know whether we'll also see the same thing in production.
One fix would be to stop asserting this - another would be to figure out what the actual maximum error message length is and raise the limit to accommodate it. I already checked the docs for
dlerror()
and it doesn't seem to say.On further investigation, the error message from
dlerror()
includes full diagnostics for which paths it tried to load - so the longer your library search path is, the more likely you will hit the limit and crash.Steps to reproduce
DYLD_LIBRARY_PATH
(we had 5 entries in it - issue didn't happen if I reduced it to 1 entry)What happens
Followed by crashing with exit code 134.
Versions in use
The text was updated successfully, but these errors were encountered: