Skip to content

Trapping UInt32 conversions when reading episodes can crash on out-of-range values #12

Description

@AlexAxthelm

Severity: minor (robustness; not reachable via current writes)

Where
iOS/Pollux/DatabaseManager.swift, episode(from:):
durationSecs: (row["duration_secs"] as Int64?).map { UInt32($0) }
and the same pattern for playback_position_secs.

Problem
UInt32(_:) traps on any value above UInt32.max. The schema CHECK constraints
enforce >= 0 but set no upper bound, so a row written by a later schema version,
external tooling, or a manual DB edit crashes the app on read — and episode(from:)
runs for every row on library load. The write path already degrades gracefully
(fileSizeBytes uses Int64(exactly:) → NULL on overflow), so read and write
currently disagree about whether bad data is survivable. There's a code comment
documenting this today.

Suggested fix
Use UInt32(exactly:) and treat overflow as nil (both fields are already
Optional), matching the write path's non-trapping behavior.

Activity

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions