gralloc: Fix array out of bound

Change-Id: I56aa8742a90d50c843707143566751ecdb7ff6ae
diff --git a/gralloc/gr_buf_mgr.cpp b/gralloc/gr_buf_mgr.cpp
index f0b4639..64f36e1 100644
--- a/gralloc/gr_buf_mgr.cpp
+++ b/gralloc/gr_buf_mgr.cpp
@@ -1356,7 +1356,7 @@
   // Reset to false for special cases below
   if (IS_VENDOR_METADATA_TYPE(metadatatype_value)) {
     metadata->isVendorMetadataSet[GET_VENDOR_METADATA_STATUS_INDEX(metadatatype_value)] = true;
-  } else {
+  } else if (GET_STANDARD_METADATA_STATUS_INDEX(metadatatype_value) < METADATA_SET_SIZE) {
     metadata->isStandardMetadataSet[GET_STANDARD_METADATA_STATUS_INDEX(metadatatype_value)] = true;
   }
 #endif
@@ -1533,7 +1533,7 @@
 #ifdef METADATA_V2
       if (IS_VENDOR_METADATA_TYPE(metadatatype_value)) {
         metadata->isVendorMetadataSet[GET_VENDOR_METADATA_STATUS_INDEX(metadatatype_value)] = false;
-      } else {
+      } else if (GET_STANDARD_METADATA_STATUS_INDEX(metadatatype_value) < METADATA_SET_SIZE) {
         metadata->isStandardMetadataSet[GET_STANDARD_METADATA_STATUS_INDEX(metadatatype_value)] =
             false;
       }