st/nine: Fix read outside bounds for some textures

According to wine tests, some apps can allocate very
small ATI1/ATI2 textures levels.

The issue is that the CPU versions of these textures are stored
in buffers which size is the same as if the format was uncompressed.

Thus the content filled cannot possibly be correct for these levels.

The tests seems to hint when rendering with these levels the output
is bad, but at least it the runtime shouldn't crash when using them.

Previously nine would read outside bounds (found with asan) in this
scenario, as the gallium helper copies a full compressed block.

Instead do not copy anything for these levels.

Signed-off-by: Axel Davy <davyaxel0@gmail.com>
Acked-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10160>
This commit is contained in:
Axel Davy 2021-03-28 18:32:15 +02:00 committed by Marge Bot
parent a6cce52908
commit f5a1f3c98d
1 changed files with 12 additions and 0 deletions

View File

@ -2550,6 +2550,18 @@ CSMT_ITEM_NO_WAIT_WITH_COUNTER(nine_context_box_upload,
/* Binding src_ref avoids release before upload */
(void)src_ref;
if (is_ATI1_ATI2(src_format)) {
const unsigned bw = util_format_get_blockwidth(src_format);
const unsigned bh = util_format_get_blockheight(src_format);
/* For these formats, the allocate surface can be too small to contain
* a block. Yet we can be asked to upload such surfaces.
* It is ok for these surfaces to have buggy content,
* but we should avoid crashing.
* Calling util_format_translate_3d would read out of bounds. */
if (dst_box->width < bw || dst_box->height < bh)
return;
}
map = pipe->transfer_map(pipe,
res,
level,