Enabled layer sanity checks in hwcomposer's prepare too
(Taken from Change-Id: Id9e970f2fb80f7eeecd2b5924d1b8e7b238e1b1d)
Bug: 72998203
Test: local
Change-Id: I2ec6edde3e0de3336d80dda1a50cb375f16c6154
diff --git a/guest/hals/hwcomposer/legacy/vsoc_composer.cpp b/guest/hals/hwcomposer/legacy/vsoc_composer.cpp
index 1eff72d..7d9856c 100644
--- a/guest/hals/hwcomposer/legacy/vsoc_composer.cpp
+++ b/guest/hals/hwcomposer/legacy/vsoc_composer.cpp
@@ -40,6 +40,10 @@
// Ensures that the layer does not include any inconsistencies
bool IsValidLayer(const vsoc_hwc_layer& layer) {
+ if (layer.flags & HWC_SKIP_LAYER) {
+ // A layer we are asked to skip is valid regardless of its contents
+ return true;
+ }
// Check displayFrame
if (layer.displayFrame.left > layer.displayFrame.right ||
layer.displayFrame.top > layer.displayFrame.bottom) {
@@ -50,6 +54,13 @@
layer.displayFrame.top, layer.displayFrame.bottom);
return false;
}
+ // Validate the handle
+ if (private_handle_t::validate(layer.handle) != 0) {
+ ALOGE("%s: Layer contains an invalid gralloc handle.", __FUNCTION__);
+ return false;
+ }
+ const private_handle_t* p_handle =
+ reinterpret_cast<const private_handle_t*>(layer.handle);
// Check sourceCrop
if (layer.sourceCrop.left > layer.sourceCrop.right ||
layer.sourceCrop.top > layer.sourceCrop.bottom) {
@@ -60,12 +71,6 @@
layer.sourceCrop.top, layer.sourceCrop.bottom);
return false;
}
- if (private_handle_t::validate(layer.handle) != 0) {
- ALOGE("%s: Layer contains an invalid gralloc handle.", __FUNCTION__);
- return false;
- }
- const private_handle_t* p_handle =
- reinterpret_cast<const private_handle_t*>(layer.handle);
if (layer.sourceCrop.left < 0 || layer.sourceCrop.top < 0 ||
layer.sourceCrop.right > p_handle->x_res ||
layer.sourceCrop.bottom > p_handle->y_res) {
@@ -594,6 +599,10 @@
VSoCComposer::~VSoCComposer() {}
int VSoCComposer::PrepareLayers(size_t num_layers, vsoc_hwc_layer* layers) {
+ if (!IsValidComposition(num_layers, layers)) {
+ LOG_FATAL("%s: Invalid composition requested", __FUNCTION__);
+ return -1;
+ }
int composited_layers_count = 0;
// Loop over layers in inverse order of z-index