Repository navigation
iOS: own every object a block hands across threads; no ARC in native checks - #6372
Open
shai-almog wants to merge 6 commits into
Open
shai-almog wants to merge 6 commits into
shai-almog wants to merge 6 commits into
Conversation
CN1OidcBrowser.m was written for ARC, but the port compiles with CLANG_ENABLE_OBJC_ARC = NO. ASWebAuthenticationSession's completion handler stored [callbackURL absoluteString] -- autoreleased into the main thread's pool -- in a __block variable and signalled the waiting thread, which then called fromNSString on it after the pool had drained. That use-after-free raised EXC_BAD_ACCESS, which ParparVM's signal handler surfaces as a NullPointerException with no message, so SystemBrowser.authenticate and OidcClient.authorize failed on device after the person approved, with OidcException transport_error "Native sign-in sheet failed: null". Under manual reference counting: - the callback string is copied and the error retained on the main thread, and both are released by the waiting thread once it has read them; - the session and its presentation context, held at +1 from -alloc, are autoreleased when the flow clears them (inside the session's own completion handler, so the session outlives the handler's return) instead of being leaked. Found in a TestFlight build of an app that signs in with OidcClient: every sign-in failed with that transport_error until the generated project was patched the same way.
The iOS native-source lint compiles with -fobjc-arc, where explicit retain/release/autorelease are errors. Guard them with __has_feature(objc_arc), so the file is correct both in the product build (ARC off) and under ARC. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SZMcbmatyXu26VSMeHqWHJ
The port builds without ARC. CN1OidcBrowser.m was not the only native that stored an autoreleased value into a __block variable from a block and read it after the block returned: - IOSNative.m: the audio recorders' error strings (freed by the block's own POOL_END before the IOException was built), openURL's string (retained under #ifdef CN1_USE_ARC -- backwards), the WKWebView snapshot image, and the watch screenshot's failure log. - CN1AR.m: createAnchorFromHit's anchor id; both anchor methods also leaked the ARAnchor. - CN1SmartHome.m: the mode-write key read in a later HomeKit completion, and the queued array walked after removeObjectForKey released it. - CN1WebAuthn.m: results alive only because the delegate leaks; now copied. How it passed: identity-stack.yml linted OIDC/AppleSignIn/WebAuthn with -fobjc-arc, the one model under which the code is correct. It now compiles them without ARC, as the target does. New gate scripts/check-ios-mrc-block-writes.py (source-gates.yml, with a unit test) reports an unowned store into a __block object variable inside a block that is read after the block. It flags master's CN1OidcBrowser.m. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…in checks The audio recorders asked requestRecordPermission: from inside their main-queue block and returned before the asynchronous answer arrived, so a first prompt produced no recorder and a denial was never reported (the Java side then waited forever). The permission is now awaited on the calling thread, before the main-queue work, and a denial throws IOException. The __block gate also reports an unowned value stored outside a block that a later block reads (CN1SmartHome.m's shape), and fails any script or workflow that compiles with -fobjc-arc: every test, lint and bench now builds without ARC, as the app does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After the one-hour timeout Java can start a second sign-in; the first session's handler then fired and autoreleased the second's session and context, which its own handler released again. A handler now clears only its own session, and a new flow cancels any abandoned one first. The ARC flag check also catches a flag followed by a file name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hie-qwfp1s # Conflicts: # Ports/iOSPort/nativeSources/CN1OidcBrowser.m
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Builds on and supersedes #6370 (its two commits are included).
The port builds with
CLANG_ENABLE_OBJC_ARC = NO. Without ARC, a__blockobject variable retains nothing, so an autoreleased value stored from a completion handler or main-queue block is freed before the waiting thread reads it. ParparVM surfaces that crash as a NullPointerException with no message.Fixes
__blockvariables are now owned:IOSNative.m: openURL, WKWebView snapshot and the audio-recorder error strings.CN1WebAuthn.m: the result and error-message strings.CN1AR.m: the anchor identifier.requestRecordPermission:was called inside the main-queue block, and the native returned before the answer arrived. A first prompt produced no recorder, a denial was never reported, andcreateMediaRecordercould wait forever. Permission is now awaited on the calling thread before the main-queue work, and a denial throwsIOException. A leakedNSFileManagerand settings dictionary are released.Why QA missed it
identity-stack.ymllinted these files with-fobjc-arc, the one model under which the original code is correct.Gates
scripts/check-ios-mrc-block-writes.py(insource-gates.yml, with a unit test):__blockobject variable inside a block that is read after the block.-fobjc-arcacross the board.// mrr: <reason>on the line.CN1OidcBrowser.mandCN1SmartHome.m.-fno-objc-arc. Choosing the flag per file for "requires ARC" natives is still allowed.Testing
scripts/pre-push-gates.sh --full: clean.scripts-iosis NOT RUN locally (CI only).identity-stack.ymlclang lint matrix (iphoneos/watchos x stubs/full) with-fno-objc-arc: clean.check-ios-private-api.py.🤖 Generated with Claude Code