Skip to content

Commit ada27a9

Browse files
author
Gopalakrishnan Nallasamy
committed
Document EPContext API placement and sample path-safety
1 parent 9ec7c5f commit ada27a9

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

include/onnxruntime/core/session/onnxruntime_c_api.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7547,6 +7547,10 @@ struct OrtApi {
75477547
* When loading a compiled model with external (non-embedded) EPContext binary data, an execution provider can
75487548
* retrieve this callback from OrtEpContextConfig and call it instead of reading the binary data from disk.
75497549
*
7550+
* Reading happens at session load, so this callback is configured on OrtSessionOptions. The corresponding write
7551+
* callback runs only at compile time and is configured on OrtModelCompilationOptions via
7552+
* OrtCompileApi::ModelCompilationOptions_SetEpContextDataWriteFunc.
7553+
*
75507554
* The state pointer is stored as-is and is not owned by ORT. It must remain valid while any session or EP created
75517555
* from these options may call the callback. If the same state may be used by multiple EPs or threads, the application
75527556
* is responsible for synchronization.
@@ -8388,6 +8392,10 @@ struct OrtCompileApi {
83888392
* When EPContext embed mode is disabled, execution providers can retrieve this callback from OrtEpContextConfig and
83898393
* call it instead of writing EPContext binary data directly to disk.
83908394
*
8395+
* Writing happens only at compile time, so this callback is configured on OrtModelCompilationOptions. The
8396+
* corresponding read callback runs at session load and is configured on OrtSessionOptions via
8397+
* OrtApi::SessionOptions_SetEpContextDataReadFunc.
8398+
*
83918399
* The state pointer is stored as-is and is not owned by ORT. It must remain valid for the duration of the compile
83928400
* operation that may call the callback. If the same state may be used by multiple EPs or threads, the application is
83938401
* responsible for synchronization.

onnxruntime/test/autoep/library/ep_context_data_utils.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ inline std::string PathToUtf8String(const std::filesystem::path& path) {
7777
#endif
7878
}
7979

80+
// NOTE: This sample resolves file_name (which can originate from an untrusted EPContext model's
81+
// "ep_cache_context" attribute) directly into a filesystem path. An absolute path or one containing ".."
82+
// segments can therefore escape the model directory. Production EPs that adopt this pattern should validate
83+
// or sandbox the resolved path (e.g. reject absolute paths and traversal, confine to an allowed directory)
84+
// and bound the amount of data read.
8085
inline OrtStatus* ResolveEpContextDataPath(const OrtApi& api, const char* file_name, const OrtGraph* graph,
8186
std::filesystem::path& data_path) {
8287
data_path.clear();

0 commit comments

Comments
 (0)