weather: guard malformed reference_time in omFileUrl
- Commit
a790a7524fb3a43c3551fbf983228409f97cdf7d- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-19 02:07 UTC (17 days ago)
- Parents
07211d8
omFileUrl sliced the server-supplied reference_time at fixed offsets with no length check. fetchOmMapMetadata only verifies the body decodes as OmMapMetadata (a plain String field), so a short or reformatted reference_time from latest.json passed decode and then threw StringIndexOutOfBoundsException inside WeatherMapState's LaunchedEffect, crashing the map. omFileUrl now returns null for values shorter than the expected timestamp layout, and the decode effect treats null like a failed decode (no overlay) instead of crashing. Verified: ./gradlew :weather:testDevUnitTest (pass), ./check weather (pass).
Diff
weather/src/main/java/com/vayunmathur/weather/domain/map/OmMapMetadata.kt
diff --git a/weather/src/main/java/com/vayunmathur/weather/domain/map/OmMapMetadata.kt b/weather/src/main/java/com/vayunmathur/weather/domain/map/OmMapMetadata.ktindex 9bed4857a9..782048d31c 100644--- a/weather/src/main/java/com/vayunmathur/weather/domain/map/OmMapMetadata.kt+++ b/weather/src/main/java/com/vayunmathur/weather/domain/map/OmMapMetadata.kt@@ -67,7 +67,10 @@ suspend fun fetchOmMapMetadata(domain: OmDomain): OmMapMetadata? { * `reference_time` `2026-07-01T18:00:00Z` → folder `2026/07/01/1800Z`; * `valid_time` `2026-07-01T18:00Z` → filename `2026-07-01T1800.om`. */-fun omFileUrl(domain: OmDomain, referenceTime: String, validTime: String): String {+fun omFileUrl(domain: OmDomain, referenceTime: String, validTime: String): String? {+ // reference_time comes from the server's latest.json; a short or+ // reformatted value must not crash the map with substring OOB.+ if (referenceTime.length < 16) return null val year = referenceTime.substring(0, 4) val month = referenceTime.substring(5, 7) val day = referenceTime.substring(8, 10)
weather/src/main/java/com/vayunmathur/weather/ui/WeatherMapState.kt
diff --git a/weather/src/main/java/com/vayunmathur/weather/ui/WeatherMapState.kt b/weather/src/main/java/com/vayunmathur/weather/ui/WeatherMapState.ktindex 8125459e4e..0b4a1fde08 100644--- a/weather/src/main/java/com/vayunmathur/weather/ui/WeatherMapState.kt+++ b/weather/src/main/java/com/vayunmathur/weather/ui/WeatherMapState.kt@@ -191,7 +191,7 @@ internal fun WeatherMapDecodeEffect(state: WeatherMapState) { state.loading = true val decoded = withContext(Dispatchers.IO) { val (w, h) = rasterSize(bbox)- val url = omFileUrl(state.domain, meta.referenceTime, validTime)+ val url = omFileUrl(state.domain, meta.referenceTime, validTime) ?: return@withContext null val t0 = System.currentTimeMillis() // Range-fetching decodeRegion(url); ranges are fetched natively in Rust. // (HttpURLConnection 64KB blocks, LRU) instead of full-file