chRyNaN / serialization-parcelable

Android Parcelable support for the Kotlinx Serialization library.
Apache License 2.0
70 stars 3 forks source link

Unmarshalling unknown type code 7340148 at offset 8 #1

Closed lepicekmichal closed 1 year ago

lepicekmichal commented 2 years ago

Describe the bug There is a bug in library that happens only on Pixel devices.

Fatal Exception: java.lang.RuntimeException: Parcel android.os.Parcel@52c801c: Unmarshalling unknown type code 6357038 at offset 8 at android.os.Parcel.readValue(Parcel.java:3305) at android.os.Parcel.readArrayMapInternal(Parcel.java:3623) at android.os.BaseBundle.initializeFromParcelLocked(BaseBundle.java:292) at android.os.BaseBundle.unparcel(BaseBundle.java:236) at android.os.Bundle.filterValues(Bundle.java:395) at android.os.Bundle.filterValues(Bundle.java:405) at android.content.Intent.removeUnsafeExtras(Intent.java:8859) at android.app.ActivityThread.handleRequestAssistContextExtras(ActivityThread.java:3890) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2171) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7839) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

I can't reproduce it, but we have a lot of bugs in firebase crashlytics. With no specific case, any screen with your parcelable between intents/fragments inside intent is potential threat.

Smartphone (please complete the following information):

Additional context It is happening with version 0.3.1, I have simultaneously upgraded to 0.4.1 and will give feedback whether it still happens.

github-actions[bot] commented 2 years ago

Welcome and thanks for contributing! Make sure to leave a detailed explanation of the issue.

chRyNaN commented 2 years ago

Thanks for bringing this up. I'll try and take a look at this tonight and see if I can track down the issue. Please test on the latest version as there was some fixes that may have resolved it.

chRyNaN commented 2 years ago

@lepicekmichal

I have tested on a Pixel 3a emulator with API 31 (Android 12) and I wasn't able to reproduce the issue. Can you provide some additional context to help debug/track down the issue? What is the Type that you are trying to serialize/deserialize? I'm seeing the following in your provided stacktrace:

at android.os.Parcel.readValue(Parcel.java:3305)
at android.os.Parcel.readArrayMapInternal(Parcel.java:3623)

So I'm assuming that the type may have been either an Array or a Map?

Also, can you provide some example code, if you are able to reproduce the issue?

chRyNaN commented 2 years ago

Relevant Android source code: ArrayMap: https://android.googlesource.com/platform/frameworks/base/+/27f592d/core/java/android/util/ArrayMap.java Parcel.readArrayMapInternal: https://android.googlesource.com/platform/frameworks/base/+/27f592d/core/java/android/os/Parcel.java#2303

lepicekmichal commented 2 years ago

Sorry it took so long to reply.

Besides all Pixels (since 3a - pro, xl, regular) it has also happened on Redmi Note 8T and POCO X3 NFC, both xiaomi. Version 0.4.1 has not fixed it.

As I said, we are unable to reproduce it either. It seems to be random based on type code number that might be conflicting with some number of yours?

The best I could find in our code would be simple usecase

@Serializable
class TextToBeFormatted(
    val text: String,
    val actions: Map<String, AppAction>,
)

@Serializable
data class AppAction(
    internal val appLink: String,
    internal val href: String? = null,
    internal val enabled: Boolean? = null,
)

using putExtra(key, value, Parcelable.Default)

lepicekmichal commented 2 years ago

I made custom serializer for this data class, which is the only one with map. So there is no map now anymore in serialization, but it still crashes the same. With readMapInternal. It has to be some bad shift inside your library.

chRyNaN commented 2 years ago

@lepicekmichal Without any more information, and being unable to reproduce this issue, there's no way to solve it. Also, what do you mean by "bad shift"? The code is open source, you can fork the library and try and track down the issue yourself. I will keep this ticket open until more details are provided or the issue is resolved.