openassistant: bound A2UI data-model growth and stepper range
- Commit
6e2098f972a038600993ae5a0b65733f925e398a- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-19 02:06 UTC (17 days ago)
- Parents
9a88fc8
Two crash paths from model-authored A2UI blocks (persisted on Message.a2ui and replayed through A2uiSurfaceView): - ComposeDataModel.setAt grew a list with while (list.size <= index) list.add(null) for any index in a bound path. A model emitting /items/2147483647 made a stepper/textfield/checkbox update try to materialize ~2^31 entries: OutOfMemoryError on the main thread (an Error, so no Exception catch saves it). Guard: refuse indices past the single append slot (index > size returns the node unchanged); existing append-at-size behavior is preserved. - QuantityStepper did (current + delta).coerceIn(min, max) with model-supplied min/max; min > max makes coerceIn throw IllegalArgumentException on the button tap. Normalize max with coerceAtLeast(min) before use. The HostSendMsg regex crash fixed in the parent commit is not touched. Verification: ./gradlew :openassistant:testDevUnitTest (BUILD SUCCESSFUL), ./check parentalcontrols openassistant (BUILD SUCCESSFUL).
Diff
openassistant/src/main/java/com/vayunmathur/openassistant/platform/A2uiComposeState.kt
diff --git a/openassistant/src/main/java/com/vayunmathur/openassistant/platform/A2uiComposeState.kt b/openassistant/src/main/java/com/vayunmathur/openassistant/platform/A2uiComposeState.ktindex 9db017a9da..e803d7e6ed 100644--- a/openassistant/src/main/java/com/vayunmathur/openassistant/platform/A2uiComposeState.kt+++ b/openassistant/src/main/java/com/vayunmathur/openassistant/platform/A2uiComposeState.kt@@ -72,6 +72,9 @@ class ComposeDataModel : A2uiCoreDataModel { val key = segments[at] val index = key.toIntOrNull() if (node is List<*> && index != null && index >= 0) {+ // Model-authored paths can name a huge index; growing the list to it OOMs.+ // Only the single append slot past the end may be materialized.+ if (index > node.size) return node val list = node.toMutableList() while (list.size <= index) list.add(null) list[index] = setAt(list[index], segments, at + 1, value)
openassistant/src/main/java/com/vayunmathur/openassistant/ui/A2uiSurfaceView.kt
diff --git a/openassistant/src/main/java/com/vayunmathur/openassistant/ui/A2uiSurfaceView.kt b/openassistant/src/main/java/com/vayunmathur/openassistant/ui/A2uiSurfaceView.ktindex 8363ab7ca9..8759787ba3 100644--- a/openassistant/src/main/java/com/vayunmathur/openassistant/ui/A2uiSurfaceView.kt+++ b/openassistant/src/main/java/com/vayunmathur/openassistant/ui/A2uiSurfaceView.kt@@ -204,7 +204,8 @@ private class SurfaceRenderer( // is dispatched on change with the new value in its context. val current = (evaluate(id, dataPath, props["value"]) as? Number)?.toDouble() ?: 0.0 val min = (props["min"] as? Number)?.toDouble() ?: 0.0- val max = (props["max"] as? Number)?.toDouble() ?: current.coerceAtLeast(min)+ // Model may emit min > max; coerceIn on an empty range throws.+ val max = ((props["max"] as? Number)?.toDouble() ?: current.coerceAtLeast(min)).coerceAtLeast(min) fun step(delta: Double) { if (!enabled) return val next = (current + delta).coerceIn(min, max)