Skip to content

fix(v3/ios): empty string from a bound method no longer crashes the app - #5626

Merged
leaanthony merged 3 commits into
masterfrom
fix/ios-empty-string-crash
Jun 17, 2026
Merged

leaanthony merged 3 commits into
masterfrom
fix/ios-empty-string-crash

Conversation

@leaanthony

@leaanthony leaanthony commented Jun 17, 2026 •

Copy link
Copy Markdown
Member

Problem

On iOS, a bound Go service method that returns an empty string immediately crashes the app (SIGABRT / abort trap).

Root cause

The iOS asset response writer (internal/assetserver/webview/responsewriter_ios.go) guarded the response-body pointer with if buf != nil:

if buf != nil {
    content = unsafe.Pointer(&buf[0])   // panics on a non-nil, zero-length slice
    contentLen = len(buf)
}

A bound method returning "" produces a zero-length but non-nil response body, which passes the != nil check — then &buf[0] panics with index-out-of-range, and the unrecovered panic aborts the Go runtime (SIGABRT). The desktop (darwin) writer already guards correctly with buf != nil && len(buf) > 0, which is why this was iOS-only.

Fix

Guard on length instead of nil (matching the desktop writers). An empty body passes a nil pointer + length 0, which is a valid empty NSData on the C side.

Verification

Reproduced on the iOS simulator: before the fix, a service method returning "" crashed to the home screen (SIGABRT confirmed in the crash report, faulting thread inside the Go runtime). After the fix, the call returns "" correctly (typeof string) and the app runs normally. Non-empty responses are byte-for-byte unchanged.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an iOS crash that occurred when a bound Go service method returns an empty string.

The iOS asset response writer guarded the body pointer with 'buf != nil'
instead of its length. A bound Go method returning "" produces a zero-length
(but non-nil) response body, so '&buf[0]' panicked with index-out-of-range and
aborted the Go runtime (SIGABRT). Guard on len(buf) instead — matching the
darwin/desktop writers — and pass a nil pointer + length 0 for an empty body
(a valid empty NSData on the C side).

Reproduced and verified fixed on the iOS simulator.
Copilot AI review requested due to automatic review settings June 17, 2026 21:05
@coderabbitai

coderabbitai Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 662bc1d2-a897-424f-8d28-61bf48a4bef5

📥 Commits

Reviewing files that changed from the base of the PR and between a076f8a and f7d6b65.

📒 Files selected for processing (2)
  • v3/UNRELEASED_CHANGELOG.md
  • v3/internal/assetserver/webview/responsewriter_ios.go

Walkthrough

In responsewriter_ios.go, the guard before taking &buf[0] is changed from buf != nil to len(buf) != 0, preventing an index-out-of-range panic when a non-nil empty slice is written. A corresponding changelog entry is added documenting the iOS SIGABRT fix.

Changes

iOS Empty-Body Response Writer Fix

Layer / File(s) Summary
Empty-slice guard in responseWriter.Write + changelog
v3/internal/assetserver/webview/responsewriter_ios.go, v3/UNRELEASED_CHANGELOG.md
The data pointer guard is changed from buf != nil to len(buf) != 0 so that &buf[0] is only taken for non-empty slices; empty bodies pass a nil pointer with length 0 to the C bridge. A "Fixed" changelog entry is added for the iOS SIGABRT crash on empty-string service method returns.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • wailsapp/wails#3590: Changes the webview responseWriter buffer handling to pass nil instead of taking &buf[0] when the buffer is empty before calling the C bridge — the same category of CGo crash fix.
  • wailsapp/wails#4576: Changes responseWriter.Write on macOS/Darwin to guard by len(buf) > 0 rather than buf != nil, the identical fix applied to the iOS writer in this PR.

Suggested labels

Bug, Documentation, size:XS

Suggested reviewers

  • makew0rld

Poem

🐇 A slice that was empty came calling one day,
The pointer said "index me!" — crash on the way.
Now length guards the gate, nil safely returns,
No SIGABRT fires, no stack trace that burns.
Hops fixed, carrots safe, the iOS app runs! 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main fix: preventing iOS crashes when a bound method returns an empty string.
Description check ✅ Passed The description comprehensively covers the problem, root cause, fix, and verification, though the template checklist sections are not explicitly marked off.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ios-empty-string-crash

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain modules listed in go.work or their selected dependencies"


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes an iOS-only crash in the v3 asset server response writer when a bound Go service method returns an empty string, by aligning the iOS response-body pointer guard with the existing desktop behavior.

Changes:

  • Update the iOS response writer to guard &buf[0] by checking len(buf) != 0 (avoids panic on non-nil, zero-length slices).
  • Add an unreleased changelog entry documenting the iOS SIGABRT fix and its root cause.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
v3/internal/assetserver/webview/responsewriter_ios.go Prevents panic on empty response bodies by guarding &buf[0] with a length check.
v3/UNRELEASED_CHANGELOG.md Documents the iOS crash fix in the “Fixed” section.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@leaanthony
leaanthony merged commit eb9bb02 into master Jun 17, 2026
12 of 15 checks passed
@leaanthony
leaanthony deleted the fix/ios-empty-string-crash branch June 17, 2026 21:23
@leaanthony leaanthony added ios Apple iOS platform mobile Mobile platform work labels Aug 9, 2026 — with ChatGPT Codex Connector
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ios Apple iOS platform mobile Mobile platform work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants