Skip to content

Possible UB in ByteString hash function #190

@MarkCMann

Description

@MarkCMann

The ByteString hash function caches previously calculated values. The member variable that stores the cached value is a non-atomic Int.

I believe that kotlinx-ios hash cache logic was inspired by the google protobuf ByteString hash implementation. But that hash caching has a disclaimer that the non-atomic Int backing the cache is safe because of JVM memory model semantics.

Is it safe to use a non-atomic Int for Kotlin native builds? Does the hash cache member variable need to be converted to an Atomic<Int> for non-JVM platforms?

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