fix(app): fixed a bug in geoip matching with refactoring. #2489
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.
As raised in #1933, the existing in-house CIDR matching mechanism can produce incorrect result in some cases. The issue was originally brought up from v2ray-core project v2fly/v2ray-core#1155. This PR ported most of the commit from the v2ray-core commit v2fly/v2ray-core#1157 by @Loyalsoldier.
Here's an example for the bug(also as a new test cases I added with the PR),
If you copy this over to the
condition_geoip_test.go
file onmain
branch, the test would fail.But this is not really expected, because
98.108.20.0/22
is from98.108.20.0
to98.108.23.255
, so it is in the range. Instead of fixing the algorithm itself, I do think it makes sense to replace the in-house algorithm with the netipx library.