microsoft/winmd

reader::filter can't handle two excludes of the same length

Closed this issue · 0 comments

The comparison predicate in reader::filter is attempting to order items in descending order of string length, and breaks ties by putting the true booleans before the false booleans.

The problem is that the predicate is ill-formed. A comparison predicate should always return false for compare(a, a) and should return false for at least one of compare(a, b) and compare(b, a). To put it another way, if compare(a, a) ever returned true, or compare(a, b) and compare(b, a) both returned true, you have an ill-formed predicate.

The filter predicate gets into this situation when there are two entries in exclude with the same string length, causing misbehavior in release and an assert in debug.

The predicate to sort needs to be updated from

return (size_compare > 0) || ((size_compare == 0) && !lhs.second);

to

return (size_compare > 0) || ((size_compare == 0) && lhs.first && !lhs.second);