From 3beb90a0fd06e0d40d58e7971d95eff7ff4c148d Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 12 Jul 2025 19:32:56 +0200 Subject: [PATCH] Fix array bounds checking in window parsing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add proper bounds checking in TerminalLauncher.swift when parsing AppleScript results - Add safe array access in WebRTCManager.swift for SDP line parsing - Add detailed error logging for debugging parsing failures - Prevents crashes when activity titles contain multiple words Fixes parsing errors like "Fixed CI build - added native dependencies" where AppleScript returns unexpected formats. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- mac/VibeTunnel/Core/Services/WebRTCManager.swift | 4 +++- mac/VibeTunnel/Utilities/TerminalLauncher.swift | 12 +++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/mac/VibeTunnel/Core/Services/WebRTCManager.swift b/mac/VibeTunnel/Core/Services/WebRTCManager.swift index b2d2917d..6e39e7f8 100644 --- a/mac/VibeTunnel/Core/Services/WebRTCManager.swift +++ b/mac/VibeTunnel/Core/Services/WebRTCManager.swift @@ -1394,7 +1394,9 @@ final class WebRTCManager: NSObject { // Look for codecs in rtpmap before processing m=video line if line.contains("rtpmap") { - let payloadType = line.components(separatedBy: " ")[0] + let components = line.components(separatedBy: " ") + guard !components.isEmpty else { continue } + let payloadType = components[0] .replacingOccurrences(of: "a=rtpmap:", with: "") if line.uppercased().contains("H264/90000") { diff --git a/mac/VibeTunnel/Utilities/TerminalLauncher.swift b/mac/VibeTunnel/Utilities/TerminalLauncher.swift index 4b37a684..56ec7cad 100644 --- a/mac/VibeTunnel/Utilities/TerminalLauncher.swift +++ b/mac/VibeTunnel/Utilities/TerminalLauncher.swift @@ -464,9 +464,15 @@ final class TerminalLauncher { let components = result.split(separator: "|").map(String.init) logger.debug("Terminal.app components: \(components)") if components.count >= 2 { - windowID = CGWindowID(components[0]) - tabReference = "tab id \(components[1]) of window id \(components[0])" - logger.info("Terminal.app window ID: \(windowID ?? 0), tab reference: \(tabReference ?? "")") + if let windowIDValue = UInt32(components[0]) { + windowID = CGWindowID(windowIDValue) + tabReference = "tab id \(components[1]) of window id \(components[0])" + logger.info("Terminal.app window ID: \(windowID ?? 0), tab reference: \(tabReference ?? "")") + } else { + logger.warning("Failed to parse window ID from components[0]: '\(components[0])'") + } + } else { + logger.warning("Unexpected AppleScript result format for Terminal.app. Expected 'windowID|tabID', got: '\(result)'. Components: \(components)") } } else if config.terminal == .iTerm2 { // iTerm2 returns window ID