yomorun / hashids-java

Hashids algorithm v1.0.0 implementation in Java
http://hashids.org
MIT License
1.02k stars 156 forks source link

ArrayIndexOutOfBoundsException issues #43

Closed ethauvin closed 7 years ago

ethauvin commented 7 years ago

Both:

Hashids hashids = new Hashids("this is my salt");
long[] numbers = hashids.decode("0");

and:

Hashids hashids = new Hashids("this is my salt");
long[] numbers = hashids.decode("test.txt");

are causing exceptions in various places.

I realize that they are not valid hashes, but the exception should either be declared or handled.

Hope this helps.

Ramblurr commented 7 years ago

I also ran into this today for the first time.

I definitely think that ArrayIndexOutOfBoundsException isn't the appropriate exception to throw. An IllegalArgumentException with an error message would be consistent with other exceptions thrown by the library.

0x3333 commented 7 years ago

I'll check on these today. I'll keep you posted on that.

0x3333 commented 7 years ago

I fixed it.

Instead throwing an exception, I return an empty array []. This is the same behavior of the original library(Javascript).

kmandeville commented 7 years ago

I have found two other occurrences where I get ArrayIndexOutOfBoundsException from deep in the HashIds code. Hashids hashids = new Hashids("this is my salt"); long[] numbers = hashids.decode("[]");

and

Hashids hashids = new Hashids("this is my salt"); long[] numbers = hashids.decode("()");

Like the original submitter above, these aren't valid hashes, but I'm running into these errors in my web app because someone COULD put these characters in as an ID in a URL accidentally or on purpose. My app is just passing in these characters directly into HashIds. I would expect something other than ArrayIndexOutOfBoundsExceptions.

Please let me know if I should open a new bug. I figured this is directly related to this issue so I'd comment here.

0x3333 commented 7 years ago

Hi @kmandeville , I'll look at this issue, but for the sake of organization, could you file another issue? Just to relate it in the commit. I'll get to work on it right away Thanks.

0x3333 commented 7 years ago

@kmandeville , never mind, I just created it(Issue #45) and fixed in master.

Thanks!

kmandeville commented 7 years ago

Thank you!