alxrm / audiowave-progressbar

Lightweight audiowave progressbar for Android
MIT License
492 stars 84 forks source link

Integer Overflow #7

Closed carmocca closed 7 years ago

carmocca commented 7 years ago

First of all, i would like to thank you for such a nice library.

I have found the source for the error you talk about in #6, specifically the one about files bigger than ~10MB. It is caused by an integer overflow in the line val currentDataIndex = targetSize * index / data.size from here. Specifically the targetSize * index multiplication. I'm not sure about why doesn't an IndexOutOfBoundsException appear when accesing the array targetSized[prevDataIndex] but i don't know much Kotlin.

It can be easily solved by casting index to long and the result to int as in (targetSize * index.toLong() / data.size).toInt() if you don't want to tweak the algorithm behind index values.

I would like to create the pull request if you are fine with it.

As a side note, the purpose of setScaledData() could be explained a little better, to me, it wasn't clear if you meant scaled as in values or size.

Thank you.

alxrm commented 7 years ago

@carmocca hey, I'm glad you've found my library useful!

I've found the source of this bug for some time ago, just haven't enough time was too lazy to fix it. You're more than welcome to send the PR with this(or any other) fix any time you want, I'll be happy to merge it and close one of the issues.

And also thank you for your contribution!