Remove redundant ORT FlatBuffer table offset validation

Merged
TI
5mo ago
+9-53

Description

Follow-up to #28186 ("Harden ORT FlatBuffer model loader against malformed buffers"). That PR added a manual ValidateRequiredTableOffsets helper that walked the raw offset array of required FlatBuffer vectors and rejected any null/zero entry while loading ORT-format models. The ORT loader already runs the generated flatbuffers::Verifier (fbs::VerifyInferenceSessionBuffer) before any deserialization in InferenceSession::LoadOrtModelWithLoader, and that verifier performs the same required-offset validation. The manual helper was therefore redundant, so this PR removes it and its call sites while keeping the existing per-entry null checks that guard the deserialization loops.

Summary of Changes

Remove redundant validation helper

FileChange
onnxruntime/core/flatbuffers/flatbuffers_utils.hRemove the ValidateRequiredTableOffsets template helper.
onnxruntime/core/flatbuffers/flatbuffers_utils.ccDrop the call in LoadOpsetImportOrtFormat.
onnxruntime/core/graph/graph.ccDrop the 5 calls (initializers, sparse initializers, node args, nodes, node edges) in Graph::LoadFromOrtFormat.
onnxruntime/core/graph/model.ccDrop the metadata-properties call in Model::LoadFromOrtFormat.

The per-entry ORT_RETURN_IF(nullptr == ..., ...) null checks inside the deserialization loops, the adversarial node-index/slot-count hardening, and the edge-bounds checks added in #28186 are all retained.

Tests

  • Remove RejectsNullNodeArgTableEntry, which only exercised the deleted helper (this case is now covered by the FlatBuffers verifier).
  • Strengthen RejectsInitializerRawDataSizeMismatch to load through the zero-copy initializer path (kOrtSessionOptionsConfigUseORTModelBytesDirectly + kOrtSessionOptionsConfigUseORTModelBytesForInitializers). The raw-data exact-size check in LoadInitializerOrtFormat is still required for that path because it bypasses the embedded TensorProto validation, and the test now covers it directly (dims{32} vs. sizeof(float) * 33 raw bytes).

Testing

make -C build/Linux/Debug -j"$(nproc)" onnxruntime_test_all
./build/Linux/Debug/onnxruntime_test_all --gtest_filter='OrtModelTest.RejectsInitializerRawDataSizeMismatch:OrtModelTest.RejectsDanglingNodeEdge:OrtModelTest.RejectsAdversarialLargeNodeIndex:OrtModelTest.RejectsInvalidEdgeEndNodeIndex:OrtModelTest.RejectsEdgeEndReferencingNullNodeSlot:OrtModelTest.RejectsGraphInputWithUnknownNodeArg'

All six focused tests pass. Behavior is unchanged for valid models; malformed buffers with null required-table offsets are still rejected, now by the FlatBuffers verifier rather than the removed helper.

Motivation and Context

Removes duplicate validation introduced in #28186 now that it is known to overlap with the FlatBuffers verifier already run on every ORT-format load. No public API or on-disk format changes.