Skip to content

WriteHandler incorrectly serializes maps of size 8 to PersistentHashMap instead of PersistentArrayMap #14

Open

Description

@IngridMorstrad

Line 189 in fressian.clj (link) is (if (< (.size kvs) 16), when it should be (if (<= (.size kvs) 16).

Important background knowledge: Clojure uses a PersistentArrayMap as the backing map if the size of the map is 8 or lower, and a PersistentHashMap otherwise.

The line of code above causes a map of size 8 to be deserialized as a PersistentHashMap. This means that when a map of size 8 is serialized, and then deserialized, the type of the map changes. Specifically, it starts off as a PersistentArrayMap, and the deserialization converts it into a PersistentHashMap. This also means that the second serialization (in a series of serialization -> deserialization -> serialization calls) will return a different value from the first one.

I can send a pull request to fix for this, but want to discuss if we should upgrade the fressian version, since making the change without a major version upgrade can cause existing clients to break (since serialization of the map of size 8 will lead to a different value with the change from < to <=).

Activity

  1. rschmitt commented on Nov 5, 2024

    @rschmitt

    This also means that the second serialization (in a series of serialization -> deserialization -> serialization calls) will return a different value from the first one.

    Different how? Field ordering?

  2. IngridMorstrad commented on Nov 5, 2024

    @IngridMorstrad
    Author

    Yes, the serialized bytes are in a different order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions