Skip to content

Commit 3526b42

Browse files
authored
[Rewriter] Prevent out of range when matching node outputs (#2508)
Trying to bind more outputs (from the pattern) than there are actual outputs of the candidate node now simply rejects the node before even trying to index into the list of node outputs. --------- Signed-off-by: Christoph Berganski <christoph.berganski@gmail.com>
1 parent f5b58e0 commit 3526b42

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

onnxscript/rewriter/_matcher.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ def _match_node(self, pattern_node: _pattern_ir.NodePattern, node: ir.Node) -> b
174174
return False
175175

176176
for i, output_value_pattern in enumerate(pattern_node.outputs):
177+
# When trying to bind more outputs (from the pattern) than there are
178+
# actual outputs of the candidate node, reject the node before even
179+
# trying to index into the list of node outputs.
180+
if i >= len(node.outputs):
181+
return False
182+
177183
if not self._match.bind_value(output_value_pattern, node.outputs[i]):
178184
return False
179185

0 commit comments

Comments
 (0)