Skip to content

Commit ceb7654

Browse files
romtsnclaude
andcommitted
fix(replay): Round Compose mask bounds outward to avoid zero-area masks
isVisible/shouldMask are derived from the sub-pixel float bounds, but the android.graphics.Rect stored on the node (and drawn by MaskRenderer) used truncating toInt(). A sub-pixel node could be marked visible+maskable yet store a zero-width/height rect, so the mask wasn't drawn and sensitive content leaked. Round outward (floor min, ceil max) so a non-empty float rect always yields a non-empty integer rect, biasing toward over-masking. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent e56c863 commit ceb7654

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

  • sentry-android-replay/src/main/java/io/sentry/android/replay/util

sentry-android-replay/src/main/java/io/sentry/android/replay/util/Nodes.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import androidx.compose.ui.layout.LayoutCoordinates
1111
import androidx.compose.ui.layout.findRootCoordinates
1212
import androidx.compose.ui.node.LayoutNode
1313
import androidx.compose.ui.text.TextLayoutResult
14+
import kotlin.math.ceil
15+
import kotlin.math.floor
1416
import kotlin.math.roundToInt
1517

1618
internal class ComposeTextLayout(internal val layout: TextLayoutResult) : TextLayout {
@@ -204,5 +206,14 @@ internal fun LayoutCoordinates.boundsInWindow(rootCoordinates: LayoutCoordinates
204206
}
205207

206208
internal fun Rect.toRect(): android.graphics.Rect {
207-
return android.graphics.Rect(left.toInt(), top.toInt(), right.toInt(), bottom.toInt())
209+
// Round outward (floor min edges, ceil max edges) so that a sub-pixel but non-empty Rect doesn't
210+
// collapse to a zero-width/height android.graphics.Rect. Otherwise a node could be marked visible
211+
// and maskable based on the float bounds, while the integer rect the MaskRenderer draws has zero
212+
// area, leaving sensitive content unmasked. Rounding outward also biases toward over-masking.
213+
return android.graphics.Rect(
214+
floor(left).toInt(),
215+
floor(top).toInt(),
216+
ceil(right).toInt(),
217+
ceil(bottom).toInt(),
218+
)
208219
}

0 commit comments

Comments
 (0)