taxi: return null instead of crashing on a malformed driver-location protobuf
- Commit
1e97508401ecf08acacaa2f80934bdf800a8b2b0- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-07 12:07 UTC (29 days ago)
- Parents
5135ec8
LyftRideParser.parseDriverLocation built its ProtoMessage outside any guard, unlike parseActiveRide right above it. A truncated or malformed protobuf body from the driver-location endpoint threw ArrayIndexOutOfBoundsException out of the parser (and out of the tracking poll that calls it) instead of degrading to no location. Found by TaxiPass3ProtoParserTest feeding the parser two garbage bytes; it crashed before the fix and returns null after. (cherry picked from commit 68067587e406b9764f1727a408cefad9839adfde)
Diff
taxi/src/main/java/com/vayunmathur/taxi/network/lyft/LyftRideParser.kt
diff --git a/taxi/src/main/java/com/vayunmathur/taxi/network/lyft/LyftRideParser.kt b/taxi/src/main/java/com/vayunmathur/taxi/network/lyft/LyftRideParser.ktindex cd43857baf..69d8c4e2f1 100644--- a/taxi/src/main/java/com/vayunmathur/taxi/network/lyft/LyftRideParser.kt+++ b/taxi/src/main/java/com/vayunmathur/taxi/network/lyft/LyftRideParser.kt@@ -120,11 +120,11 @@ internal class LyftRideParser(private val json: Json) { fun parseDriverLocation(resp: RawResponse): DriverLocation? { val contentType = resp.header("Content-Type")?.lowercase().orEmpty() val isProto = contentType.contains("protobuf") || contentType.contains("octet-stream")- fun proto(): DriverLocation? {+ fun proto(): DriverLocation? = runCatching { val root = ProtoMessage(resp.bytes, 0, resp.bytes.size) // ReadDriverLocationResponse.location = 1; tolerate a bare DriverLocation too.- return root.message(1)?.let(::toDriverLocationProto) ?: toDriverLocationProto(root)- }+ root.message(1)?.let(::toDriverLocationProto) ?: toDriverLocationProto(root)+ }.getOrNull() fun asJson(): DriverLocation? { val root = runCatching { json.parseToJsonElement(resp.text) as? JsonObject }.getOrNull() ?: return null