Skip to content

fix: CoreML EP crash when loading model with external data file#28043

Open
Scottcjn wants to merge 1 commit intomicrosoft:mainfrom
Scottcjn:fix/coreml-external-data-path
Open

fix: CoreML EP crash when loading model with external data file#28043
Scottcjn wants to merge 1 commit intomicrosoft:mainfrom
Scottcjn:fix/coreml-external-data-path

Conversation

@Scottcjn
Copy link
Copy Markdown

Fixes #28005

CoreML EP crashes with SIGBUS when loading models that use external data files (.onnx_data). CPU EP works fine which is what tipped me off that it was provider-specific.

The bug is in TensorProtoWithExternalDataToTensorProto() -- it passes model_path straight to ReadExternalDataForTensor() but model_path is the full file path like /path/to/model.onnx not the directory. So GetExternalDataInfo() builds a garbage path like /path/to/model.onnx/model.onnx_data.

Fix is model_path.parent_path() instead. Same thing UnpackInitializerData() already does at line ~2572. Only affects CoreML EP since thats the only caller passing a non-empty path here.

- ORT_RETURN_IF_ERROR(ReadExternalDataForTensor(ten_proto, model_path, unpacked_data));
+ ORT_RETURN_IF_ERROR(ReadExternalDataForTensor(ten_proto, model_path.parent_path(), unpacked_data));

…path

TensorProtoWithExternalDataToTensorProto() passes model_path (full file
path like "/path/to/model.onnx") directly to ReadExternalDataForTensor(),
which expects a directory. This causes GetExternalDataInfo() to construct
invalid paths like "/path/to/model.onnx/model.onnx_data" instead of
"/path/to/model.onnx_data".

The bug only affects the CoreML EP because it's the only production caller
that passes a non-empty model_path. CPU EP uses UnpackInitializerData()
which correctly calls model_path.parent_path().

Fix: use model_path.parent_path(), matching the established pattern at
line ~2572.

Fixes microsoft#28005

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CoreML EP: SIGBUS crash when loading model with external data file via CreateSession

1 participant