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

Stricter check for Shape's input: check input type #3757

Merged
merged 1 commit into from Oct 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 13 additions & 11 deletions onnx/defs/tensor/defs.cc
Expand Up @@ -433,18 +433,20 @@ ONNX_OPERATOR_SET_SCHEMA(
auto* output_shape = ctx.getOutputType(0)->mutable_tensor_type()->mutable_shape();
auto* output_length = output_shape->add_dim();

if (ctx.getInputType(0)->tensor_type().has_shape()) {
int64_t rank = static_cast<int64_t>(ctx.getInputType(0)->tensor_type().shape().dim_size());
int64_t start = getAttribute(ctx, "start", 0);
if (start < 0)
start += rank;
start = (start < 0) ? 0 : (start > rank) ? rank : start;
int64_t end = getAttribute(ctx, "end", rank);
if (end < 0)
end += rank;
end = (end < 0) ? 0 : (end > rank) ? rank : end;
output_length->set_dim_value((end - start) < 0 ? 0 : (end - start));
if (!hasNInputShapes(ctx, 1)) {
return;
}

int64_t rank = static_cast<int64_t>(ctx.getInputType(0)->tensor_type().shape().dim_size());
int64_t start = getAttribute(ctx, "start", 0);
if (start < 0)
start += rank;
start = (start < 0) ? 0 : (start > rank) ? rank : start;
int64_t end = getAttribute(ctx, "end", rank);
if (end < 0)
end += rank;
end = (end < 0) ? 0 : (end > rank) ? rank : end;
output_length->set_dim_value((end - start) < 0 ? 0 : (end - start));
})
.PartialDataPropagationFunction([](DataPropagationContext& ctx) {
if (ctx.getInputType(0)->tensor_type().has_shape()) {
Expand Down