Guard nil asset.contentURL in ETCoreMLModel initWithAsset:#20338
Conversation
Summary: Fixes EXC_BAD_ACCESS / KERN_INVALID_ADDRESS in `-[ETCoreMLModel initWithAsset:configuration:orderedInputNames:orderedOutputNames:error:]` at `xplat/executorch/backends/apple/coreml/runtime/delegate/ETCoreMLModel.mm:197`. MID: `2bcd0a9cec05c99079249d043c273b07` — https://www.internalfb.com/logview/facebook_ios_fads/2bcd0a9cec05c99079249d043c273b07 Context from MID: 3,094 occurrences in the past 7 days, first seen 2026-04-01, last seen 2026-06-11. Surfaced in the `FBVideoHomeUnifiedPlayerViewController:warion_vdd_feed` Scuba slice (https://fburl.com/scuba/errorreporting_facebook_ios_fads/0x31y7si) but the actual fault is in the ExecuTorch CoreML delegate, not the player VC. Root cause: the initializer calls `[asset keepAliveAndReturnError:]` which validates the asset's file lock but does not validate that `asset.contentURL` is non-nil. When the compiled `.mlmodelc` was reaped from disk between the lock and the load (or the asset was never fully materialized), `asset.contentURL` returns nil. `+[MLModel modelWithContentsOfURL:configuration:error:]` does not tolerate a nil URL — it deref's into CoreML internals and faults. Fix: capture `asset.contentURL` into a local, return nil with `ETCoreMLErrorCorruptedModel` populated in the out-error if the URL is nil. No behavior change for valid assets — callers already handle the documented `nil` + `error` contract. Reviewed By: metascroy Differential Revision: D108334793
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/20338
Note: Links to docs will display an error until the docs builds have been completed. ❌ 4 New Failures, 1 Pending, 1 Unrelated FailureAs of commit 8cce690 with merge base 0eb8247 ( NEW FAILURES - The following jobs have failed:
FLAKY - The following job failed but was likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@KushalAdhvaryu has exported this pull request. If you are a Meta employee, you can view the originating Diff in D108334793. |
|
This PR needs a
|
Summary:
Fixes EXC_BAD_ACCESS / KERN_INVALID_ADDRESS in
-[ETCoreMLModel initWithAsset:configuration:orderedInputNames:orderedOutputNames:error:]atxplat/executorch/backends/apple/coreml/runtime/delegate/ETCoreMLModel.mm:197.Root cause: the initializer calls
[asset keepAliveAndReturnError:]which validates the asset's file lock but does not validate thatasset.contentURLis non-nil. When the compiled.mlmodelcwas reaped from disk between the lock and the load (or the asset was never fully materialized),asset.contentURLreturns nil.+[MLModel modelWithContentsOfURL:configuration:error:]does not tolerate a nil URL — it deref's into CoreML internals and faults.Fix: capture
asset.contentURLinto a local, return nil withETCoreMLErrorCorruptedModelpopulated in the out-error if the URL is nil. No behavior change for valid assets — callers already handle the documentednil+errorcontract.Reviewed By: metascroy
Differential Revision: D108334793