Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
GeoIPMatcher的匹配逻辑是先把CIDR从小到大排序,然后用折半查找的方式检查目标IP是否被包含,但CIDR的排序逻辑有点问题,遇到IP相同而掩码不同的时候,把掩码小的排在前面,这就导致IP可能会匹配失败。
设想目前CIDRList排序后是这样:["98.108.20.0/22", "98.108.20.0/23"],匹配98.108.22.11就会失败,因为折半时刚好从元素[1]开始,这时匹配失败,继续往后找已经没有更多元素了。
所以排序的正确顺序是这样:["98.108.20.0/23", "98.108.20.0/22"],也就是把掩码大的排在前面