fix: handle(_:) がパスの短い URL で Index out of range になる問題を修正 - #11
Open
masaru87 wants to merge 1 commit into
Open
Conversation
isAcceptableURL(url:) は pathComponents.isEmpty のみを確認していたが、 handle(_:) は pathComponents[1] と、success の場合は pathComponents[2] を 読むため、要素数が 1 または 2 の URL でクラッシュしていた。
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.
Studyplus.handle(_:)に、パスの要素数が足りない URL を渡すとIndex out of rangeでクラッシュする箇所がありました。再現
isAcceptableURL(url:)はpathComponents.isEmptyのみを確認していますが、handle(_:)はpathComponents[1]を、successの場合はさらにpathComponents[2]を読みます。そのため要素数が 1 または 2 の URL が通過してしまいます。studyplus-{key}://auth-result[]studyplus-{key}://auth-result/["/"]pathComponents[1]でクラッシュstudyplus-{key}://auth-result/success["/", "success"]pathComponents[2]でクラッシュstudyplus-{key}://auth-result/success/{token}["/", "success", "{token}"]README の案内どおり AppDelegate で受け取った URL をそのまま
handle(_:)に渡す使い方だと、カスタム URL スキームは他のアプリからも開けるため、上のような URL を渡されるとアプリが終了してしまいます。変更内容
isAcceptableURL(url:)でpathComponents.count < 2を弾くようにしました(handle(_:)が[1]を読むため)case "success"でpathComponents.count >= 3を確認し、足りない場合は他の受け付けられない URL と同じくstudyplusLoginFail(error: .unknownUrl(url))を呼んでfalseを返すようにしました確認したこと
手元に Xcode 環境がないため、
handle(_:)とisAcceptableURL(url:)のロジックをそのまま書き写したものを Swift 6.3 (macOS) で実行して確認しました。Fatal error: Index out of range(SIGTRAP で終了).unknownUrlでfalseを返します。success/{token}・fail・cancelの 3 ケースは変更前後で挙動が変わりません.swiftlint.ymlでswiftlint lintを実行し、新たな警告が出ないことも確認していますテストターゲットが定義されていないようでしたので、この PR にはテストを追加していません。追加した方がよければ対応します。