Fix out-of-bounds read in optimizer passes with zero-element initializers#27976
Open
GopalakrishnanN wants to merge 1 commit intomicrosoft:mainfrom
Open
Fix out-of-bounds read in optimizer passes with zero-element initializers#27976GopalakrishnanN wants to merge 1 commit intomicrosoft:mainfrom
GopalakrishnanN wants to merge 1 commit intomicrosoft:mainfrom
Conversation
…zers Multiple graph optimizer passes crashed with SIGSEGV when processing zero-element constant initializers (shape [0], 0 bytes of data). These are valid ONNX tensors that pass validation but caused out-of-bounds memory access when data<T>()[0] was dereferenced without checking size(). Fixes: - div_mul_fusion.cc: Changed size() > 1 to size() != 1 to reject both zero-element and multi-element initializers - layer_norm_fusion.cc: Added size() > 0 guard before epsilon access in both LayerNormFusion and SimplifiedLayerNormFusion passes, falling back to DEFAULT_LAYERNORM_EPSILON for zero-element initializers - dropout_elimination.cc: Added size() == 0 early return before ratio data access - double_qdq_pairs_remover.cc: Added size() == 0 checks for zero-point and scale initializers in FindNewZeroPointAndScale and ApplyNewInputValue - utils.cc: Added size() == 0 check in GetClipConstantMinMax before accessing Clip min/max initializer data Tests: - Added 4 regression tests verifying zero-element initializers don't crash DivMulFusion, NoopElimination, LayerNormFusion, and SimplifiedLayerNormFusion passes
Contributor
|
@GopalakrishnanN please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
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
Multiple graph optimizer passes crashed with SIGSEGV when processing zero-element constant initializers (shape
[0], 0 bytes of data). These are valid ONNX tensors that pass validation but caused out-of-bounds memory access whendata<T>()[0]was dereferenced without checkingsize().This is the same bug pattern fixed in
relu_clip_fusion.ccby PR #26878, but the fix was never propagated to these passes.Fixes
size() > 1tosize() != 1to reject both zero-element and multi-element initializerssize() > 0guard before epsilon access in both LayerNormFusion and SimplifiedLayerNormFusion passes, falling back toDEFAULT_LAYERNORM_EPSILONsize() == 0early return before ratio data accesssize() == 0checks for zero-point and scale initializerssize() == 0check inGetClipConstantMinMaxbefore accessing Clip min/max initializer dataTests
Added 4 regression tests verifying zero-element initializers don't crash:
DivMulFusion_ZeroElementInitializer_NoCrashNoopElimination_ZeroElementInitializer_NoCrashLayerNormFusion_ZeroElementEpsilon_NoCrashSimplifiedLayerNormFusion_ZeroElementEpsilon_NoCrashAll 48 related optimizer tests pass (44 pre-existing + 4 new).