Validate ORT format string initializers (#32751)
This pull request strengthens validation for string data in tensor
initializers and sparse tensors, and refactors related utility functions
for clarity and correctness. The changes ensure that string data is
properly checked for size mismatches and that unsupported cases (such as
string-valued sparse tensors) are explicitly rejected, both in code and
tests.
Validation and error handling improvements:
* Added explicit rejection of sparse tensors with string data type in
both `SparseTensorProtoToDenseTensorProto` and
`LoadSparseInitializerOrtFormat`, returning a clear error message for
unsupported types.
[[1]](diffhunk://#diff-d31e9fbe0f5334fcd949833e035f2b25d5ae810dcd505c545f6b372b546b1406R2565-L2570)
[[2]](diffhunk://#diff-874fcf6fe9ebccf6c75081a092e7bccaa641548c80d5ba07c1430df667878454R473-R475)
* In `LoadInitializerOrtFormat`, added a check to ensure the number of
string data entries matches the expected element count, with a
descriptive error if there is a mismatch.
Refactoring and utility improvements:
* Refactored tensor element counting by extracting logic into a new
`GetElementCountFromFbsTensor` function, and updated
`GetSizeInBytesFromFbsTensor` to use it, improving code clarity and
separation of concerns.
[[1]](diffhunk://#diff-874fcf6fe9ebccf6c75081a092e7bccaa641548c80d5ba07c1430df667878454L215-R221)
[[2]](diffhunk://#diff-874fcf6fe9ebccf6c75081a092e7bccaa641548c80d5ba07c1430df667878454L240-R237)
[[3]](diffhunk://#diff-874fcf6fe9ebccf6c75081a092e7bccaa641548c80d5ba07c1430df667878454R263-R286)
Test coverage enhancements:
* Added new tests to verify rejection of mismatched string data sizes
and unsupported string-valued sparse tensors in flatbuffer utility and
sparse tensor conversion code.
[[1]](diffhunk://#diff-0720de3aed302feade21de676a30b15fd01ed3b99bc6873813f3c6f22f753d93R334-R396)
[[2]](diffhunk://#diff-bf60b675d31eecac530b68e6a39deeb210327a6d319fe85f282568bcb5dc19ffR2842-R2863)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>