-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
java.lang.ArrayIndexOutOfBoundsException #586
Comments
Interesting, we haven't seen this before. We could expand our check when we create the file (https://github.com/segmentio/analytics-android/blob/master/analytics/src/main/java/com/segment/analytics/SegmentIntegration.java#L132-L142). Catching more general exceptions could lead to other bugs though, so it would be good to understand why this is happening. |
@f2prateek I agree that catching the exception would not be a good approach. I will try to spend a bit more time to see if I can reproduce it myself |
We have been experiencing this crash for a while now, and in quite large volumes. It also seems to be the same issue as what is raised here: #627 I dug further into the cause and have a suggestion for a more targeted fix. Here are the conclusions I was able to draw.
I worked backwards to figure out if any of these cases are true starting with
This means that either If we step down into
We know We also know that So position is greater than or equal to Which means it is possible to get into a situation where But it is important to note that this isn’t easy to achieve. As
When I changed the contents of
In this case I set I attempted to see if there were any obvious cases where such a large value was sneaking into the header. But I didn't have much luck. Outside of The most likely culprit would be something in Ultimately I think that further digging is likely burnt effort at this point. Considering it only seems to occur on Android 9, there is probably something suspect happening at the OS level and not anything wrong with the actual write logic. It seems best to expand the corrupt file checks around I.e. update
I am happy to raise a PR: @f2prateek are you still the right person to talk to about this? |
Hi, @seaplain , thanks for your debugging and detailed comment. @f2prateek is no longer actively maintaining this repo. However, I am now doing some maintenance work for Segment on this repo though I am new to this codebase. A PR would be most welcome and I will review. |
Thanks @aultimus I'll put up a PR asap and aim to create some test cases for it too. I am not certain why this could happen. I narrowed it down to either an external corruption of the file or some edge case where adding / removing to the QueueFile can leave it in an invalid state. I believe it is the former because we only see this crash on Android 9 devices. But ultimately yes for this to happen the values stored in the file must be invalid. I'm not confident I have enough knowledge of the codebase and problem-space to debug any further than that. I do have a device that matches the crashes we have seen but I wasn't able to reproduce it myself. |
…tOffset and lastOffset. This will resolve an `ArrayIndexOutOfBoundsException` (segmentio#586) crash in Android 9 devices as IOExceptions are handled by `SegmentIntegration.createQueueFile`.
…lues (#646) * Adding checks to readHeader for invalid values in the header for firstOffset and lastOffset. This will resolve an `ArrayIndexOutOfBoundsException` (#586) crash in Android 9 devices as IOExceptions are handled by `SegmentIntegration.createQueueFile`. * Fixing formatting violations Co-authored-by: Coby Plain <cplain@.atlassian.com>
…lues (#646) * Adding checks to readHeader for invalid values in the header for firstOffset and lastOffset. This will resolve an `ArrayIndexOutOfBoundsException` (#586) crash in Android 9 devices as IOExceptions are handled by `SegmentIntegration.createQueueFile`. * Fixing formatting violations Co-authored-by: Coby Plain <cplain@.atlassian.com>
Hi, could you please try release 4.5.0-beta.2 which should address this issue. I am closing this issue, please re-open if the problem persists https://github.com/segmentio/analytics-android/releases/tag/4.5.0-beta.2 |
We have started seeing this causing a crash using V 4.3.0 on Android P in production. Unfortunately I have yet to reproduce this issue myself.
The text was updated successfully, but these errors were encountered: