Use non-optional UUID init for zero-IDFA sentinel#472
Closed
yusuftor wants to merge 1 commit into
Closed
Conversation
UUID(uuidString:) returns Optional, which would silently make the equality check at the call site false if the literal ever failed to parse — the zero-IDFA sentinel would then slip through unfiltered. Switch to UUID(uuid:) which takes the 16-byte tuple directly and returns a non-optional, removing the optionality from the comparison without resorting to force-unwrap. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment on lines
+59
to
+61
| // Non-optional construction via `init(uuid:)` — `init(uuidString:)` returns | ||
| // an Optional which would make the equality check silently false-positive | ||
| // if the literal ever failed to parse. |
There was a problem hiding this comment.
The comment says "silently false-positive" but the failure mode is a false-negative: if
zeroAdvertisingIdentifier were nil, the equality check would return false, the if block would not fire, and the all-zeros IDFA would pass through unfiltered — the opposite of a false-positive.
Suggested change
| // Non-optional construction via `init(uuid:)` — `init(uuidString:)` returns | |
| // an Optional which would make the equality check silently false-positive | |
| // if the literal ever failed to parse. | |
| // Non-optional construction via `init(uuid:)` — `init(uuidString:)` returns | |
| // an Optional which would make the equality check silently false-negative | |
| // (zero-IDFA passes through unfiltered) if the literal ever failed to parse. |
Prompt To Fix With AI
This is a comment left during a code review.
Path: Sources/SuperwallKit/Analytics/Attribution/AttributionFetcher.swift
Line: 59-61
Comment:
The comment says "silently false-positive" but the failure mode is a false-negative: if `zeroAdvertisingIdentifier` were `nil`, the equality check would return `false`, the `if` block would not fire, and the all-zeros IDFA would pass through unfiltered — the opposite of a false-positive.
```suggestion
// Non-optional construction via `init(uuid:)` — `init(uuidString:)` returns
// an Optional which would make the equality check silently false-negative
// (zero-IDFA passes through unfiltered) if the literal ever failed to parse.
```
How can I resolve this? If you propose a fix, please make it concise.
Collaborator
Author
|
Pushed directly to develop instead — see commit 1c81ac5. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #470. The reviewer flagged that
private static let zeroAdvertisingIdentifier = UUID(uuidString: "...")types the constant asUUID?— if the literal ever failed to parse (impossible for this constant, but the type allows it), the equality check at the call site would benil != identifierValue → falseand the zero-IDFA would slip through unfiltered.UUIDhas a non-optionalinit(uuid: uuid_t)that takes the 16-byte tuple directly. Switching to that removes the optionality without needing a force-unwrap.Test plan
🤖 Generated with Claude Code
Greptile Summary
This PR swaps the zero-IDFA sentinel constant from
UUID(uuidString:)(which producesUUID?) toUUID(uuid:)with a 16-byte all-zero tuple (which produces a non-optionalUUID), closing a theoretical type-safety gap introduced in PR #470.zeroAdvertisingIdentifieris now typed asUUIDrather thanUUID?, so the==comparison againstidentifierValueis unambiguous and can never silently evaluate tofalsedue to aniloptional.Confidence Score: 5/5
Safe to merge — the one-line constant change correctly removes optionality from the zero-IDFA sentinel, and the only finding is a word choice error in the explanatory comment.
The fix is minimal, targeted, and mechanically correct:
UUID(uuid:)with all-zero bytes produces the same value as the old string literal but as a non-optional type, so the equality check is now unconditionally well-typed. The only thing flagged is that the comment describes the failure mode as a 'false-positive' when it is actually a false-negative.No files require special attention.
Important Files Changed
UUID(uuidString:)(returnsUUID?) withUUID(uuid:)(returnsUUID) for the zero-IDFA sentinel constant, eliminating the optionality and making the equality check unconditionally correct. Only issue is a minor terminology error in the new comment.Sequence Diagram
sequenceDiagram participant Caller participant AttributionFetcher participant ASIdentifierManager Caller->>AttributionFetcher: identifierForAdvertisers AttributionFetcher->>ASIdentifierManager: adsIdentifier ASIdentifierManager-->>AttributionFetcher: UUID? (nil or value) alt adsIdentifier is nil AttributionFetcher-->>Caller: nil else adsIdentifier is UUID AttributionFetcher->>AttributionFetcher: "identifierValue == zeroAdvertisingIdentifier (UUID == UUID, always valid)" alt identifierValue is all-zeros sentinel AttributionFetcher-->>Caller: nil (filtered) else identifierValue is real IDFA AttributionFetcher-->>Caller: identifierValue.uuidString end endPrompt To Fix All With AI
Reviews (1): Last reviewed commit: "Use non-optional UUID init for zero-IDFA..." | Re-trigger Greptile