Remove redundant ORT FlatBuffer table offset validation#29068
Merged
Conversation
skottmckay
approved these changes
Jun 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Follow-up to #28186 ("Harden ORT FlatBuffer model loader against malformed buffers"). That PR added a manual
ValidateRequiredTableOffsetshelper 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 generatedflatbuffers::Verifier(fbs::VerifyInferenceSessionBuffer) before any deserialization inInferenceSession::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
onnxruntime/core/flatbuffers/flatbuffers_utils.hValidateRequiredTableOffsetstemplate helper.onnxruntime/core/flatbuffers/flatbuffers_utils.ccLoadOpsetImportOrtFormat.onnxruntime/core/graph/graph.ccGraph::LoadFromOrtFormat.onnxruntime/core/graph/model.ccModel::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
RejectsNullNodeArgTableEntry, which only exercised the deleted helper (this case is now covered by the FlatBuffers verifier).RejectsInitializerRawDataSizeMismatchto load through the zero-copy initializer path (kOrtSessionOptionsConfigUseORTModelBytesDirectly+kOrtSessionOptionsConfigUseORTModelBytesForInitializers). The raw-data exact-size check inLoadInitializerOrtFormatis still required for that path because it bypasses the embeddedTensorProtovalidation, and the test now covers it directly (dims{32}vs.sizeof(float) * 33raw bytes).Testing
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.