Skip to content

Fix off-by-one in app group identifier length check for POSIX semaphore prefix#113

Open
taichino wants to merge 2 commits intoobjectbox:mainfrom
bloom:fix_prefix_length_check
Open

Fix off-by-one in app group identifier length check for POSIX semaphore prefix#113
taichino wants to merge 2 commits intoobjectbox:mainfrom
bloom:fix_prefix_length_check

Conversation

@taichino
Copy link
Copy Markdown

Summary

On sandboxed macOS, Store.init reads the app's entitlements and picks the first
application group identifier that fits within the POSIX semaphore name budget.
The current filter checks $0.length <= 20 before appending "/", but
obx_posix_sem_prefix_set requires the total prefix (including "/") to be at most
20 characters. A group ID of exactly 20 characters passes the filter, becomes 21
after appending, and is rejected by the C library.

The rejected call sets thread-local error state, and because the return value of
obx_posix_sem_prefix_set is not checked, this stale error propagates into
Store.init via checkLastError(), causing initialization to fail with
illegalArgument("Given prefix must not exceed 20 chars").

This was discovered in a production app whose shortest app group identifier is
exactly 20 characters (team ID + "." + 9-char name).

Changes

  • Changed the length filter from <= 20 to <= 19 to account for the appended "/"
  • Updated the comment to clarify that the limit applies to the full prefix including "/"

Testing

This is not covered by a unit test because setUpMutexIdentifier reads entitlements
from the running binary's code signature at runtime, which cannot be controlled in a
test environment. The fix is verified by code inspection.

@greenrobot-team
Copy link
Copy Markdown
Member

Thanks for this! We should probably also change this to work like in the Dart API where a missing slash suffix is added before the length check.

For our reference this is internal issue objectbox-swift#351

@taichino
Copy link
Copy Markdown
Author

Thanks for the suggestion! I've updated the PR to match the Dart API approach.
I also extracted the logic into a static func semaphorePrefix(from:) so it's unit testable.

@greenrobot-team

@greenrobot-team
Copy link
Copy Markdown
Member

@taichino I didn't expect you to make these changes (hence the "we" as in the ObjectBox team), so thank you! We will look at picking these changes when there is time!

@greenrobot-team greenrobot-team added the bug Something isn't working label Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants