From 2d023068fe99d992933225a6722f3ec5a280fc94 Mon Sep 17 00:00:00 2001 From: Dan Stoza Date: Mon, 9 Apr 2018 12:14:55 -0700 Subject: Region: Speculative fix for ubsan abort Adds a special case to Region::end() to handle mStorage being empty. By design, this should never happen, but something seems to be causing it to happen, so instead of allowing the ubsan abort to take down SurfaceFlinger, we work around the issue by special-casing size() == 0. Bug: 77643177 Test: By design this shouldn't happen, so it's not yet clear how to write a test to exercise it Change-Id: Ifaae2eb8e89460319e599205cd64f00d120279b8 --- libs/ui/Region.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libs/ui/Region.cpp b/libs/ui/Region.cpp index 36da084c80..fe4ae6c414 100644 --- a/libs/ui/Region.cpp +++ b/libs/ui/Region.cpp @@ -838,6 +838,11 @@ Region::const_iterator Region::begin() const { } Region::const_iterator Region::end() const { + // Workaround for b/77643177 + // mStorage should never be empty, but somehow it is and it's causing + // an abort in ubsan + if (mStorage.isEmpty()) return mStorage.array(); + size_t numRects = isRect() ? 1 : mStorage.size() - 1; return mStorage.array() + numRects; } -- cgit v1.2.3-59-g8ed1b