You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SEC-2576: ArrayIndexOutOfBoundsException in IpAddressMatcherΒ #2790
When dealing with performance issues in our software we looked a little bit deeper in the sources of IpAddressMatcher class. We figured out that the matches-methods will throw an ArrayIndexOutOfBoundsException when the netmask length given at construction time is too large. "Too large" means the netmask byte array is longer the byte array obtained from the ip address.
See attached test class (ArrayIndexOutOfBoundsExceptionTest).
We think to fix these Exception is quite easy, if the byte array for the netmask is determined at construction time and some basic checks are added. (We expect this solution will also perform better if the matches method of an already constructed IpAddressMatcher is called more than once.)
Attached IpAddressMatcher class contains these changes.
For informational purposes we submit the attached IpAddressMatcher2 class with some more performance optimizations (... and API changes). These changes are only seen useful for our special needs.
Agreed that this is an issue. To address it, I think the code should validate the constructor input. For example, it should assert that the requiredAddress byte length times 8 is greater than or equal to nMaskBits.
Activity
jzheaux commentedon Jul 3, 2019
Agreed that this is an issue. To address it, I think the code should validate the constructor input. For example, it should assert that the
requiredAddressbyte length times 8 is greater than or equal tonMaskBits.The code should do the same for
remoteAddress.clementkng commentedon Jul 4, 2019
Hi @jzheaux, can I try taking this issue?
jzheaux commentedon Jul 4, 2019
Yes, of course, @clementkng! I'm looking forward to your PR.
Throws exception when passed IP address with too long mask
Throws exception when passed IP address with too long mask