commit 126d02deb1c131d2a2bae5523e915f3b4e7e857b
parent 94ca358a4fd5334920d4abb1634f7ea39d70309f
Author: Miao Bin <bin.miao@intel.com>
Date: Thu, 8 Jan 2026 17:35:31 +0000
Bug 2008822 [wpt PR 57024] - WebNN: Replace null characters in operand names for ORT backend, a=testonly
Automatic update from web-platform-tests
WebNN: Replace null characters in operand names for ORT backend
Input and output operand names starting with null characters ('\0')
cause ORT's CreateValueInfo API to fail with "name cannot be null or
empty string" error [1], leading to context lost.
Furthermore, ORT's C API truncates at any '\0' and this happens before
we append the operand id. For example, both 'input\0a_1' and
'input\0b_2' would become 'input', which will lead to “Duplicate
definition-site for (input)” error.
This CL replaces all '\0' characters with '_' in operand names to ensure
compatibility with ORT's C API (name collisions are prevented by the
joined unique operand id).
This CL also adds WPT tests to cover null characters in different
positions.
[1] https://github.com/microsoft/onnxruntime/blob/7b5a93ef5f71ca58a1b6e4ae81b250e767756c68/onnxruntime/core/session/model_editor_c_api.cc#L29
Bug: 470831369
Change-Id: I3f833d2398ecd8cd3e5b4f106fb0b7c1b25f2485
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7298368
Reviewed-by: Rafael Cintron <rafael.cintron@microsoft.com>
Commit-Queue: Miao, Bin <bin.miao@intel.com>
Reviewed-by: Hu, Ningxin <ningxin.hu@intel.com>
Cr-Commit-Position: refs/heads/main@{#1565393}
--
wpt-commits: 2d00123f9d72e0c18fa3110aec3893931b00c83b
wpt-pr: 57024
Diffstat:
1 file changed, 31 insertions(+), 0 deletions(-)
diff --git a/testing/web-platform/tests/webnn/conformance_tests/inputs-with-special-names.https.any.js b/testing/web-platform/tests/webnn/conformance_tests/inputs-with-special-names.https.any.js
@@ -24,6 +24,8 @@ const specialNameArray = [
// Escape Sequence
'hello\n\t\r\b\f\v\'\"\0\\webnn',
+ '\0',
+ '\0startWithNullCharacter',
// Hexadecimal Escape Sequences
// '\x41'→ 'A'
@@ -72,3 +74,32 @@ specialNameArray.forEach((name) => {
Float32Array.from([2, 1, 1, 2]));
}, `abs input with special character name '${name}'`);
});
+
+promise_test(async () => {
+ const builder = new MLGraphBuilder(mlContext);
+ const inputA = builder.input('input\0a', { dataType: 'float32', shape: [2] });
+ const inputB = builder.input('input\0b', { dataType: 'float32', shape: [2] });
+ const output = builder.add(inputA, inputB);
+
+ const [inputATensor, inputBTensor, outputTensor, mlGraph] = await Promise.all([
+ mlContext.createTensor({ dataType: 'float32', shape: [2], writable: true }),
+ mlContext.createTensor({ dataType: 'float32', shape: [2], writable: true }),
+ mlContext.createTensor({ dataType: 'float32', shape: [2], readable: true }),
+ builder.build({ 'output': output })
+ ]);
+
+ const inputAData = Float32Array.from([1, 1]);
+ const inputBData = Float32Array.from([2, 2]);
+ mlContext.writeTensor(inputATensor, inputAData);
+ mlContext.writeTensor(inputBTensor, inputBData);
+
+ const inputs = { 'input\0a': inputATensor, 'input\0b': inputBTensor };
+ mlContext.dispatch(mlGraph, inputs, { 'output': outputTensor });
+
+ // Wait for graph execution to complete.
+ await mlContext.readTensor(outputTensor);
+
+ assert_array_equals(
+ new Float32Array(await mlContext.readTensor(outputTensor)),
+ Float32Array.from([3, 3]));
+}, `[add] inputs with null character name in the middle`);