fix(ios): stop ForEach indices race in row lists and validate driver port range#1094
Merged
fix(ios): stop ForEach indices race in row lists and validate driver port range#1094
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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
Two distinct production crashes hit by TestFlight users on TableProMobile build 10/11. Both fixed in this PR.
Crash 1 —
Array._checkSubscript/ "Index out of range"Stack trace (build 11, iPhone 15, iOS 26.4.1):
Root cause:
ForEach(rows.indices, id: \.self) { index in ... rows[index] ... }. SwiftUI capturesrows.indicesonce butrowsis a computed property readingviewModel.legacyRows. When the array shrinks during a SwiftUI update pass (page change, filter, deletion), ForEach still iterates the stale indices androws[index]traps. CLAUDE.md flags this exact pattern as a "Performance Pitfall".Fix: introduce
IndexedRow: Identifiablewrapper (Helpers/IndexedRow.swift) and iterate[IndexedRow]instead. SwiftUI diffs by stable id; if rows shrink, the missing ids are removed cleanly without ever subscripting a stale offset. Applied to all three sites:DataBrowserView,QueryEditorView,RowDetailView.Crash 2 —
Swift runtime failure: Not enough bits to represent the passed valueStack trace (build 10, iPhone 16):
Root cause:
mysql_real_connect(..., UInt32(port), ...)whereport: Int. If the connection's port is negative or > UInt32.max,UInt32(port)traps. The form parses port viaInt(portString) ?? 3306— a typed-1slips through. Same shape exists inRedisDriver(Int32(port)).Fix: validate
portis in1...65_535before each driver-level integer cast and throw a readableconnectionFailedinstead of trapping. Applied to MySQL, Redis, and PostgreSQL (consistency — PG was string-interpolating so it didn't crash, but it silently passed garbage to libpq).Test plan
-1or99999999999, save, tap connect. Expect a readable error sheet, no crash.RowDetailView) work as before.Files changed
TableProMobile/Helpers/IndexedRow.swift(new) — Identifiable wrapperTableProMobile/Views/DataBrowserView.swift— useIndexedRow.wrapTableProMobile/Views/QueryEditorView.swift— useIndexedRow.wrapTableProMobile/Views/RowDetailView.swift— useIndexedRow.wrapTableProMobile/Drivers/MySQLDriver.swift— port range guard beforeUInt32(port)TableProMobile/Drivers/RedisDriver.swift— port range guard beforeInt32(port)TableProMobile/Drivers/PostgreSQLDriver.swift— port range guard (parity / readable error)CHANGELOG.md— Fixed entries