Commit 525fde75 by Doug Horn Committed by Commit Bot

Fix potential mod by 0 with invalid formats.

If the format passed to MakeValidSize is invalid, there is potential for a mod by 0 which can result in a crash. Test: Verify no crash when format is invalid. Bug: b/182823289 Change-Id: I7f538be5d984070984f5581a5cc7ea47264109f4 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2780557Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Doug Horn <doughorn@google.com>
parent 010d61f2
...@@ -2129,10 +2129,12 @@ void MakeValidSize(bool isImage, ...@@ -2129,10 +2129,12 @@ void MakeValidSize(bool isImage,
int *levelOffset) int *levelOffset)
{ {
const DXGIFormatSize &dxgiFormatInfo = d3d11::GetDXGIFormatSizeInfo(format); const DXGIFormatSize &dxgiFormatInfo = d3d11::GetDXGIFormatSizeInfo(format);
bool validFormat = format != DXGI_FORMAT_UNKNOWN;
bool validImage = isImage && validFormat;
int upsampleCount = 0; int upsampleCount = 0;
// Don't expand the size of full textures that are at least (blockWidth x blockHeight) already. // Don't expand the size of full textures that are at least (blockWidth x blockHeight) already.
if (isImage || *requestWidth < static_cast<GLsizei>(dxgiFormatInfo.blockWidth) || if (validImage || *requestWidth < static_cast<GLsizei>(dxgiFormatInfo.blockWidth) ||
*requestHeight < static_cast<GLsizei>(dxgiFormatInfo.blockHeight)) *requestHeight < static_cast<GLsizei>(dxgiFormatInfo.blockHeight))
{ {
while (*requestWidth % dxgiFormatInfo.blockWidth != 0 || while (*requestWidth % dxgiFormatInfo.blockWidth != 0 ||
...@@ -2143,7 +2145,7 @@ void MakeValidSize(bool isImage, ...@@ -2143,7 +2145,7 @@ void MakeValidSize(bool isImage,
upsampleCount++; upsampleCount++;
} }
} }
else else if (validFormat)
{ {
if (*requestWidth % dxgiFormatInfo.blockWidth != 0) if (*requestWidth % dxgiFormatInfo.blockWidth != 0)
{ {
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "libANGLE/renderer/d3d/d3d11/Context11.h" #include "libANGLE/renderer/d3d/d3d11/Context11.h"
#include "libANGLE/renderer/d3d/d3d11/Renderer11.h" #include "libANGLE/renderer/d3d/d3d11/Renderer11.h"
#include "libANGLE/renderer/d3d/d3d11/formatutils11.h" #include "libANGLE/renderer/d3d/d3d11/formatutils11.h"
#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
#include "libANGLE/renderer/d3d/d3d11/texture_format_table.h" #include "libANGLE/renderer/d3d/d3d11/texture_format_table.h"
#include "libANGLE/renderer/dxgi_support_table.h" #include "libANGLE/renderer/dxgi_support_table.h"
#include "test_utils/ANGLETest.h" #include "test_utils/ANGLETest.h"
...@@ -153,6 +154,31 @@ TEST_P(D3D11FormatTablesTest, TestFormatSupport) ...@@ -153,6 +154,31 @@ TEST_P(D3D11FormatTablesTest, TestFormatSupport)
} }
} }
// This test validates that all DXGI_FORMATs can be potentially resized without crashes.
TEST_P(D3D11FormatTablesTest, TestFormatMakeValidSize)
{
gl::Context *context = static_cast<gl::Context *>(getEGLWindow()->getContext());
rx::Context11 *context11 = rx::GetImplAs<rx::Context11>(context);
rx::Renderer11 *renderer = context11->getRenderer();
const gl::FormatSet &allFormats = gl::GetAllSizedInternalFormats();
for (GLenum internalFormat : allFormats)
{
const rx::d3d11::Format &formatInfo =
rx::d3d11::Format::Get(internalFormat, renderer->getRenderer11DeviceCaps());
std::array<bool, 2> isImages = {false, true};
for (auto &image : isImages)
{
int reqWidth = 32;
int reqHeight = 32;
int level = 0;
rx::d3d11::MakeValidSize(image, formatInfo.texFormat, &reqWidth, &reqHeight, &level);
}
}
}
ANGLE_INSTANTIATE_TEST(D3D11FormatTablesTest, ANGLE_INSTANTIATE_TEST(D3D11FormatTablesTest,
ES2_D3D11_FL9_3(), ES2_D3D11_FL9_3(),
ES2_D3D11_FL10_0(), ES2_D3D11_FL10_0(),
......
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