matomo-org / matomo-sdk-android

SDK for Android to measure your apps with Matomo. Works on Android phones, tablets, Fire TV sticks, and more!
BSD 3-Clause "New" or "Revised" License
388 stars 162 forks source link

okhttp writeByte ArrayIndexOutOfBoundsException: length=8192 #197

Closed huangliqiang closed 6 years ago

huangliqiang commented 6 years ago

i use org.piwik.sdk:piwik-sdk:2.0.0 has this cash log :: cash with org.piwik.sdk.dispatcher.Dispatcher.dispatch

java.lang.ArrayIndexOutOfBoundsException: length=8192; index=8192
    at com.android.okhttp.okio.Buffer.writeByte(Buffer.java:973)
    at com.android.okhttp.internal.Platform.concatLengthPrefixed(Platform.java:134)
    at com.android.okhttp.internal.Platform.configureTlsExtensions(Platform.java:88)
    at com.android.okhttp.internal.http.SocketConnector.connectTls(SocketConnector.java:99)
    at com.android.okhttp.Connection.connect(Connection.java:143)
    at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:185)
    at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:128)
    at com.android.okhttp.internal.http.HttpEngine.nextConnection(HttpEngine.java:342)
    at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:331)
    at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:249)
    at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:437)
    at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:114)
    at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:245)
    at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218)
    at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:25)
    at org.piwik.sdk.dispatcher.Dispatcher.dispatch(Dispatcher.java)
    at org.piwik.sdk.dispatcher.Dispatcher$1.run(Dispatcher.java)
    at java.lang.Thread.run(Thread.java:818)
d4rken commented 6 years ago

Does it also occur with the latest version?

The exception itself is not a piwik issue, but it should not crash the library. Did it crash the library? I can't tell from your stacktrace where the exception originates, as there are no line numbers for the library.

huangliqiang commented 6 years ago

@d4rken i wan to use the 2.0library the exception at org.piwik.sdk.dispatcher.Dispatcher.dispatch(Dispatcher.java) if you try catch(ArrayIndexOutOfBoundsException) at Dispatcher.java 253line , will useful?

d4rken commented 6 years ago

Why do yo not want to use v3.0?

There will be no extra releases for v2.X, but you are of course free to fork the repo and make the changes yourself.

The error itself is likely a bug in an older version of okhttp that has been packaged with Android itself:

https://github.com/square/okhttp/issues/3194 https://github.com/square/okhttp/issues/1776

This is still interesting to fix for v3.X. To fix this we can either include okhttp explicitly, to get newer versions, or catch the error as you suggested which is what others have also been doing: https://github.com/mozilla-mobile/telemetry-android/commit/37bff7dce90e54f3a4dbe0e1f8cc3d53bc827402

I guess it depends on how much overhead the explicit depenency on okhttp is. I think it would not be worth it just to fix this...

huangliqiang commented 6 years ago

@d4rken Thank you for your answer。 i donot wan to use v3.0 because this version neet to update Android studio 3.0, but i wan to use Android studio 2.2.3. and i think v3.0 also has the exception, the two versions are very different.

This problem has affected my releases APK operation. if this : mozilla-mobile/telemetry-android@37bff7d suggestion is useful, can you update this code for v2.0 and v3.0 version ? Thank you very much.

d4rken commented 6 years ago

The issue is not present on v3.0 due to the wider catch: https://github.com/matomo-org/piwik-sdk-android/blob/master/piwik-sdk/src/main/java/org/piwik/sdk/dispatcher/DefaultPacketSender.java#L62

I don't want to support multiple update tracks. There will be no legacy version fixes. You can either upgrade to 3.0 or fork 2.0 and apply the changes yourself.

Sorry that I can't be of more help.