ail: Assert that the mip level is in bounds
authorAsahi Lina <lina@asahilina.net>
Fri, 9 Dec 2022 11:15:42 +0000 (20:15 +0900)
committerMarge Bot <emma+marge@anholt.net>
Sat, 17 Dec 2022 18:10:28 +0000 (18:10 +0000)
This preempts possible out-of-bounds accesses and later asserts when
trying to get the tile size.

Signed-off-by: Asahi Lina <lina@asahilina.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20365>

src/asahi/layout/tiling.c

index 359e9f8..c4fa25c 100644 (file)
@@ -158,6 +158,7 @@ ail_detile(void *_tiled, void *_linear,
    unsigned height_px = u_minify(tiled_layout->height_px, level);
    unsigned blocksize_B = util_format_get_blocksize(tiled_layout->format);
 
+   assert(level < tiled_layout->levels && "Mip level out of bounds");
    assert(tiled_layout->tiling == AIL_TILING_TWIDDLED && "Invalid usage");
    assert((sx_px + swidth_px) <= width_px && "Invalid usage");
    assert((sy_px + sheight_px) <= height_px && "Invalid usage");
@@ -175,6 +176,7 @@ ail_tile(void *_tiled, void *_linear,
    unsigned height_px = u_minify(tiled_layout->height_px, level);
    unsigned blocksize_B = util_format_get_blocksize(tiled_layout->format);
 
+   assert(level < tiled_layout->levels && "Mip level out of bounds");
    assert(tiled_layout->tiling == AIL_TILING_TWIDDLED && "Invalid usage");
    assert((sx_px + swidth_px) <= width_px && "Invalid usage");
    assert((sy_px + sheight_px) <= height_px && "Invalid usage");