Skip to content

Commit eb9bb02

Browse files
authored
fix(v3/ios): empty string from a bound method no longer crashes the app (#5626)
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.
1 parent 98efc33 commit eb9bb02

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

v3/UNRELEASED_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ After processing, the content will be moved to the main changelog and this file
2323

2424
## Fixed
2525
<!-- Bug fixes -->
26+
- Fix an iOS crash (SIGABRT) 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, so a zero-length body made `&buf[0]` panic; it now guards on length, matching the desktop writers
2627

2728
## Deprecated
2829
<!-- Soon-to-be removed features -->

v3/internal/assetserver/webview/responsewriter_ios.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ func (rw *responseWriter) Write(buf []byte) (int, error) {
103103

104104
var content unsafe.Pointer
105105
var contentLen int
106-
if buf != nil {
106+
// Guard on length, not just nil: a non-nil but empty slice (e.g. the body of
107+
// a bound method that returned "") would make &buf[0] panic with an
108+
// index-out-of-range, aborting the Go runtime. An empty body is valid — pass
109+
// a nil pointer with length 0, which yields an empty NSData on the C side.
110+
if len(buf) != 0 {
107111
content = unsafe.Pointer(&buf[0])
108112
contentLen = len(buf)
109113
}

0 commit comments

Comments
 (0)