Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Relax] Fix segfault in rewrite_bindings for MatchCast node #17226

Conversation

Lunderberg
Copy link
Contributor

Prior to this commit, the tvm.relax.dpl.rewrite_bindings utility would segfault if its input contained a DataflowBlock whose first binding was a MatchCast.

The root cause is use of an unintialized const VarNode* cur_user_; when collecting the variable usage. This variable is only initialized for VarBinding nodes, and may be used uninitialized if a MatchCast node is encountered before the first VarBinding. This uninitialized value is later dereferenced during while pattern-matching, causing a segfault.

This commit provides a default value of nullptr for MatcherUseDefAnalysis::cur_user_, preventing the segfault.

Prior to this commit, the `tvm.relax.dpl.rewrite_bindings` utility
would segfault if its input contained a `DataflowBlock` whose first
binding was a `MatchCast`.

The root cause is use of an unintialized `const VarNode* cur_user_;`
when collecting the variable usage.  This variable is only initialized
for `VarBinding` nodes, and may be used uninitialized if a `MatchCast`
node is encountered before the first `VarBinding`.  This uninitialized
value is later dereferenced during while pattern-matching, causing a
segfault.

This commit provides a default value of `nullptr` for
`MatcherUseDefAnalysis::cur_user_`, preventing the segfault.
@Lunderberg Lunderberg merged commit 24cd93d into apache:main Aug 1, 2024
19 checks passed
@Lunderberg Lunderberg deleted the bugfix_uninitialized_pointer_in_rewrite_bindings branch August 1, 2024 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants