Bugfix: Avoid potential crash from force-unwrap of pointOrigin in pan gesture#33897
Open
rm335 wants to merge 1 commit into
Open
Bugfix: Avoid potential crash from force-unwrap of pointOrigin in pan gesture#33897rm335 wants to merge 1 commit into
rm335 wants to merge 1 commit into
Conversation
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.
💡 Description
Fixes a potential crash in the Tracking Protection menus where
pointOrigin!was force-unwrapped insidepanGestureRecognizerAction(sender:). The property is optional and only initialized inviewDidLayoutSubviews, so if the pan gesture fires before the first layout pass (e.g. after a memory warning, a rapid present/dismiss cycle, or in automated UI tests) the app crashes withEXC_BAD_INSTRUCTION.The same bug pattern existed in two files (duplicated code path):
firefox-ios/Client/Frontend/Browser/EnhancedTrackingProtection/EnhancedTrackingProtectionVC.swift— line 495firefox-ios/Client/Frontend/TrackingProtection/TrackingProtectionViewController.swift— line 707The fix
The force-unwrap is replaced with the same safe-fallback pattern the surrounding code already uses just a few lines later (L504 / L716), defaulting to the current view origin (
originalYPosition) whenpointOriginhas not yet been set:Behavior is identical in the common case where
pointOriginhas been initialized (which is the only case the previous code handled correctly). Only the previously-crashing edge case is corrected.Regression tests
Two new test files exercise the gesture handler with
pointOriginstill nil (i.e. beforeviewDidLayoutSubviewsran) and verify the call no longer crashes:firefox-ios/firefox-ios-tests/Tests/ClientTests/TrackingProtectionTests/EnhancedTrackingProtectionVCTests.swiftfirefox-ios/firefox-ios-tests/Tests/ClientTests/TrackingProtectionTests/TrackingProtectionViewControllerTests.swiftBoth test files follow the existing
TrackingProtectionTeststest-suite pattern (XCTest,@MainActor,@testable import Client,DependencyHelperMock().bootstrapDependencies()) and use aMockPanGestureRecognizertest double to drive the handler deterministically.🎥 Demos
N/A — no visual change. Behavior is identical when
pointOriginis set (the common case). Only the previously-crashing edge case is corrected.Static-grep verification
📝 Checklist