aco: fix uninitialized data in the binary
authorRhys Perry <pendingchaos02@gmail.com>
Tue, 24 Sep 2019 16:21:51 +0000 (17:21 +0100)
committerRhys Perry <pendingchaos02@gmail.com>
Mon, 13 Jan 2020 13:25:32 +0000 (13:25 +0000)
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-By: Timur Kristóf <timur.kristof@gmail.com>
Fixes: 93c8ebfa780 ('aco: Initial commit of independent AMD compiler')
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3081>

src/amd/compiler/aco_interface.cpp

index 802adcefb1bee6bab2d7c91104bee1899db67ff1..f951c4fdc5f54aa9b2037a9848384aea7ed3e670 100644 (file)
@@ -154,7 +154,11 @@ void aco_compile_shader(unsigned shader_count,
    }
 
    size += code.size() * sizeof(uint32_t) + sizeof(radv_shader_binary_legacy);
-   radv_shader_binary_legacy* legacy_binary = (radv_shader_binary_legacy*) malloc(size);
+   /* We need to calloc to prevent unintialized data because this will be used
+    * directly for the disk cache. Uninitialized data can appear because of
+    * padding in the struct or because legacy_binary->data can be at an offset
+    * from the start less than sizeof(radv_shader_binary_legacy). */
+   radv_shader_binary_legacy* legacy_binary = (radv_shader_binary_legacy*) calloc(size, 1);
 
    legacy_binary->base.type = RADV_BINARY_TYPE_LEGACY;
    legacy_binary->base.stage = shaders[shader_count-1]->info.stage;