mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-14 20:48:00 +00:00
[js/web][Fix] - updating the C API to catch non-tensor data (#12811)
Added a check for tensor validation on the input - this change fixes the quiet abort WASM takes when processing a non tensor data in "OrtGetTensorData" **Motivation and Context** At the current status when we try to process non-tensor data through OrtGetTensorData and exception is thrown which results in a quiet abort from WASM (assuming WASM was built without exception handling). I added a check in the C API to catch this case and output a meaningful message to the user [example_error_github_12622.zip](https://github.com/microsoft/onnxruntime/files/9464328/example_error_github_12622.zip)
This commit is contained in:
parent
8de5535e9c
commit
851b0ce936
2 changed files with 8 additions and 2 deletions
|
|
@ -328,7 +328,7 @@ export const run =
|
|||
errorCode = wasm._OrtGetTensorData(
|
||||
tensor, tensorDataOffset, tensorDataOffset + 4, tensorDataOffset + 8, tensorDataOffset + 12);
|
||||
if (errorCode !== 0) {
|
||||
throw new Error(`Can't get a tensor data. error code = ${errorCode}`);
|
||||
throw new Error(`Can't access output tensor data. error code = ${errorCode}`);
|
||||
}
|
||||
let tensorDataIndex = tensorDataOffset / 4;
|
||||
const dataType = wasm.HEAPU32[tensorDataIndex++];
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ OrtSessionOptions* OrtCreateSessionOptions(size_t graph_optimization_level,
|
|||
RETURN_NULLPTR_IF_ERROR(EnableOrtCustomOps, session_options);
|
||||
#endif
|
||||
#if defined(USE_XNNPACK)
|
||||
|
||||
|
||||
RETURN_NULLPTR_IF_ERROR(SessionOptionsAppendExecutionProvider, session_options, "XNNPACK", nullptr, nullptr, 0);
|
||||
#endif
|
||||
return session_options;
|
||||
|
|
@ -246,6 +246,12 @@ int OrtGetTensorData(OrtValue* tensor, int* data_type, void** data, size_t** dim
|
|||
size_t* p_dims = nullptr;
|
||||
void* p_string_data = nullptr;
|
||||
|
||||
ONNXType tensor_type;
|
||||
RETURN_ERROR_CODE_IF_ERROR(GetValueType, tensor, &tensor_type);
|
||||
if ( tensor_type != ONNX_TYPE_TENSOR ) {
|
||||
return ORT_FAIL;
|
||||
}
|
||||
|
||||
RETURN_ERROR_CODE_IF_ERROR(GetTensorTypeAndShape, tensor, &info);
|
||||
|
||||
size_t dims_len = 0;
|
||||
|
|
|
|||
Loading…
Reference in a new issue