Skip to content

serializeAnchor uses deprecated NSKeyedArchiver.archivedData(withRootObject:) — breaks anchor decoding with modern NSKeyedUnarchiver #348

@motudev

Description

@motudev

Summary

serializeAnchor in ios/Serializers.swift encodes HKQueryAnchor using the deprecated NSKeyedArchiver.archivedData(withRootObject:) API (no requiringSecureCoding

 // Current (buggy)
 let data = NSKeyedArchiver.archivedData(withRootObject: anchor)

The modern replacement NSKeyedUnarchiver.unarchivedObject(ofClass:from:) internally
sets requiresSecureCoding = true. When it encounters an archive written without that flag
it silently returns nil (via try?), not an error.

Any native code that reads back an anchor written by this library using the modern unarchiver
will silently get nil, treating every query as if no anchor exists. The result is a full
re-sync from the beginning instead of an incremental delta

Affected versions

Confirmed in v12.1.2 and v14.0.0. Helpers.swift in v14 still has the same pattern:

func toBase64(_ data: Any?) -> String? {
  if let data = data {
    let data = NSKeyedArchiver.archivedData(withRootObject: data)
    let encoded = data.base64EncodedString()

    return encoded
  }

  return nil
}

PR: #349

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