Commit f60da874 by David Benjamin Committed by Commit Bot

Fix out-of-bounds access bug in ANGLE tests

When not filled in, as in Android, activeGPUIndex is -1. This is fine for Android because it doesn't use vendorID, but the function computed vendorID unconditionally without checking for -1. Default activeGPUIndex to 0 instead of -1. Note code still needs to check for systemInfo.gpus.empty(). This caused crashes when _LIBCPP_DEBUG=0 was enabled. Bug: chromium:923166 Change-Id: If4d1dff9553a580fd92bc0497fc092789d07ed93 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1925031Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jonah Ryan-Davis <jonahr@google.com>
parent 6e4004dd
......@@ -59,8 +59,9 @@ struct SystemInfo
std::vector<GPUDeviceInfo> gpus;
// Index of the GPU expected to be used for 3D graphics. Based on a best-guess heuristic on
// some platforms. On windows, this is accurate.
int activeGPUIndex = -1;
// some platforms. On Windows, this is accurate. Note `gpus` must be checked for empty before
// indexing.
int activeGPUIndex = 0;
bool isOptimus = false;
bool isAMDSwitchable = false;
......
......@@ -541,7 +541,7 @@ TEST_P(DrawBaseVertexBaseInstanceTest, DrawArraysInstancedBaseInstance)
if (IsAMD() && IsWindows() && IsDesktopOpenGL())
{
SystemInfo *systemInfo = GetTestSystemInfo();
if (!(systemInfo->activeGPUIndex < 0 || systemInfo->gpus.empty()))
if (!systemInfo->gpus.empty())
{
ANGLE_SKIP_TEST_IF(0x6613 == systemInfo->gpus[systemInfo->activeGPUIndex].deviceId);
}
......
......@@ -351,13 +351,7 @@ inline bool GetActiveGPU(GPUDeviceInfo **devInfo)
{
return false;
}
// Default to the first index
uint32_t index = 0;
// See if the activeGPUIndex was set first
if (systemInfo->activeGPUIndex != -1)
{
index = systemInfo->activeGPUIndex;
}
uint32_t index = systemInfo->activeGPUIndex;
ASSERT(index < systemInfo->gpus.size());
*devInfo = &(systemInfo->gpus[index]);
return true;
......
......@@ -96,7 +96,7 @@ bool HasSystemVendorID(VendorID vendorID)
{
SystemInfo *systemInfo = GetTestSystemInfo();
// Unfortunately sometimes GPU info collection can fail.
if (systemInfo->activeGPUIndex < 0 || systemInfo->gpus.empty())
if (systemInfo->gpus.empty())
{
return false;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment