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
Fix panic in setproduct when one of the arguments is an empty list #103
Fix panic in setproduct when one of the arguments is an empty list #103
Conversation
…d test to exercise codepath
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this! I left a comment inline about the exact solution to the problem.
cty/function/stdlib/collection.go
Outdated
@@ -953,7 +953,7 @@ var SetProductFunc = function.New(&function.Spec{ | |||
// If any of the arguments was an empty collection then our result | |||
// is also an empty collection, which we'll short-circuit here. | |||
if retType.IsListType() { | |||
return cty.ListValEmpty(ety).Mark(retMarks), nil | |||
return cty.ListValEmpty(ety), nil | |||
} | |||
return cty.SetValEmpty(ety).Mark(retMarks), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the correct change here, as it will result in dropping marks from input values.
Instead, I think the crash is caused by calling Mark
with a cty.ValueMarks
value, instead of calling WithMarks
. Unfortunately the compiler didn't catch this because Mark
accepts interface{}
.
Would you mind fixing this up to call WithMarks
for both the empty list and empty set branches? Adding tests cases to cover this would be great too. Input of two empty lists marked "a" and "b" respectively should result in an empty list marked with both "a" and "b", and the same for sets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @alisdair thanks for your input! I think you're right. I'll fix this :)
Thanks for working on this @thehunt33r, and thanks @alisdair for reviewing! This also looks good to me, with the updates Alisdair suggested, and so I'm going to merge it now. Thanks again! |
Hi!
This PR fixes: #102
When one of the argument of
setproduct
is an empty list, we would get this panic:I think the reason for this is that in
function/stdlib/collection.go
, in the case of an argument being an empty collection, an empty list was returned. However that list was first run through.Mark
which caused the panic since there are no marks.I've also taken the liberty of adding a test which helped me exercise this panic. The short-circuit codepath wasn't exercised previously.
I've made sure that all the tests are still passing after my change.
Thanks!