Five Bugs Caught by an 8-Way Adversarial Review Before Flick 2.0.1
An 8-subagent adversarial code review right before Flick 2.0.1 (commit 00a4aa1) uncovered a silent byte-cap bypass on iOS 17–26, a zoom-resize focus snap, orphaned undo batches, an integer-overflow crash in tampered ledgers, and solid-color images flagged as blurry.
Right before shipping Flick 2.0.1, I ran an 8-way parallel adversarial review across the codebase (commit 00a4aa1). Everything looked fine in normal device testing, yet reading specifically for broken invariants, OS version gaps, hostile inputs, and torn state caught five real bugs.
1. The 100 MB Free Byte Cap Never Bound on iOS 17–26
PhotoAsset.swift computed resource sizes like this:
if #available(iOS 27, macOS 27, *) {
knownSizes = resources.compactMap { $0.dataSize.map(Int64.init) }
}
PHAssetResource.dataSize was introduced in iOS 27, and the new SDK removed fileSize from the public Swift interface. With no else branch, knownSizes evaluated to [] on iOS 17 through iOS 26, making every asset’s quotaBytes evaluate to 0. The 100 MB free-tier byte limit never triggered.
Adding the fallback branch—reading ($0.value(forKey: "fileSize") as? NSNumber)?.int64Value via KVC, the exact key releases through v1.8 used—restored real byte counting on iOS 17–26, while flagging unreadable resources as estimated instead of silently charging 0.
2. Resizing a Zoomed Photo Snapped Focus Back to Top-Left
After a window resize or orientation change, ZoomImageScrollView.swift calls restoreFocus(_:) to keep the inspected region centered.
It was clamping contentOffset against the unzoomed contentSize, even though contentOffset lives in the rendered (zoomed) coordinate space—just as centerContent() computes centering insets from zoomed bounds. On resize while zoomed in, the tighter unzoomed clamp collapsed the offset to the top-left corner.
Replacing the hand-rolled math with renderedSize = imageView.convert(imageView.bounds, to: self).size passed into ZoomViewportTransform.contentOffset(focus:imageSize:viewport:) kept geometry in one tested helper.
3. Restoring From the Pending Bin Left Phantom Progress—and Orphaned Undo Batches
CleanupSession.swift and PendingBinScreen.swift had three state-drift bugs:
- Phantom
+1in progress: Removing a photo from the Pending Bin (session.restore(_:)) updatedpendingandreviewedIDs, but never calledProgressTracker.undoLastDecision(recordedAt:). The “Reviewed” counter kept a phantom+1.restore(_:)now returns the original decision’srecordedAtdate so callers roll backProgressTrackerin lockstep. - Orphaned batch undo entries: Staging a duplicate group appended transient
.deleterecords tohistory. Dismissing the undo banner (dismissBatchFeedback()) or staging another batch left those.deleteentries behind—leavingnextUndoAssetIDpointing at an already-staged photo and disabling single-step undo on the swipe deck. Both paths now purge transient batch history viaremoveBatchHistory(_:). - Torn backup wipeout:
reviewedBackup.v1used synthesizedCodable. If the app was killed mid-write afteridsflushed but beforeremovedIDsandisCompletewere written, the next launch threwkeyNotFoundand threw away the user’s entire review history. Switching to a hand-writteninit(from:)withdecodeIfPresentrecoversidscleanly.
4. A Corrupted Allowance Ledger Could Trap on Launch
FreeCleanupUsage is persisted in the Keychain, UserDefaults, and iCloud KVS—all user-writable on a jailbroken device.
If a corrupted or tampered payload stored Int.max or Int64.max, usedPhotos + batchPhotos in FreeCleanupPolicy.allowsDelete and grow-only merges would trap under Swift’s checked + operator and crash the app.
Two changes closed it:
FreeCleanupUsage.initclamps persisted values tomaxCount = 10_000_000andmaxBytes = 1 << 40(1 TiB), far above any legitimate free-tier ledger.FreeCleanupPolicy.allowsDeletenow compares against remaining headroom in subtraction form:batchPhotos <= freePhotoLimit - min(usedPhotos, freePhotoLimit).
While reviewing FreeCleanupCloudKV, we also noticed writes overwrote baseline directly instead of max-merging with the existing KVS record, letting a device with a stale v1 total downgrade the shared baseline.
5. Solid-Color Frames Scored 0.0 and Got Pre-Selected as Blurry
BlurScorer.swift divides Laplacian variance by grayscale variance. A textureless frame—an accidental lens-cap shot, a blank whiteboard—has lapVar near 0.
Returning 0.0 caused the classifier to treat it as “definitively blurry” and pre-select it for deletion. Blur is undefined without texture, so guard lapVar > 1e-9 else { return nil } now reports it as unknown instead. At the same time, lowering the imgVar floor from 1.0 to 1e-6 fixed false blur flags on sharp low-contrast images like blue skies and white walls, whose normalized UInt8 variance was below 1.0.
Two Bonus Hardening Fixes
The same pass moved AnalysisCoordinator’s consecutiveLoadFailures = 0 reset inside runTask (ending a MainActor race with a previously cancelled task), and added a Swift source scan to scripts/check-privacy.py so calling systemUptime, attributesOfFileSystem, or activeInputModes without declaring them in PrivacyInfo.xcprivacy fails CI instead of App Store Connect upload.
Happy-path tests rarely catch an Int.max plist or a missing #available else branch—explicitly looking for ways to break your own invariants does.
Comments