From 8b620227499cd843779a286a0d733b56022adcea Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Thu, 24 Dec 2020 11:36:05 +0100 Subject: [PATCH] backdrop: avoid a (benign) zero-sized read Found with MEM_DEBUG added in later change. Signed-off-by: Elias Naur --- piet-gpu/shader/backdrop.comp | 20 +++++++++++--------- piet-gpu/shader/backdrop.spv | Bin 7752 -> 7840 bytes 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/piet-gpu/shader/backdrop.comp b/piet-gpu/shader/backdrop.comp index f57d6e0..fb01d0d 100644 --- a/piet-gpu/shader/backdrop.comp +++ b/piet-gpu/shader/backdrop.comp @@ -85,16 +85,18 @@ void main() { el_ix = probe; } } - uint seq_ix = row - (el_ix > 0 ? sh_row_count[el_ix - 1] : 0); uint width = sh_row_width[el_ix]; - // Process one row sequentially - // Read backdrop value per tile and prefix sum it - uint tile_el_ix = sh_row_base[el_ix] + seq_ix * 2 * width; - uint sum = memory[tile_el_ix]; - for (uint x = 1; x < width; x++) { - tile_el_ix += 2; - sum += memory[tile_el_ix]; - memory[tile_el_ix] = sum; + if (width > 0) { + // Process one row sequentially + // Read backdrop value per tile and prefix sum it + uint seq_ix = row - (el_ix > 0 ? sh_row_count[el_ix - 1] : 0); + uint tile_el_ix = sh_row_base[el_ix] + seq_ix * 2 * width; + uint sum = memory[tile_el_ix]; + for (uint x = 1; x < width; x++) { + tile_el_ix += 2; + sum += memory[tile_el_ix]; + memory[tile_el_ix] = sum; + } } } } diff --git a/piet-gpu/shader/backdrop.spv b/piet-gpu/shader/backdrop.spv index 72b24bf01fb41395717af80456da0e14334f2038..e71fd9b5c06cb42cf09a8c4cd09eb3ea34054251 100644 GIT binary patch delta 1291 zcmYk5OKVe66ot=Cnx@9Yx7Mastu<=3YHcTiM#$K)<4z2;P!(xKLF5*3CW6p`11Ew5 z2P#Fqg3X)XWG)()qg?UeM1l54DP+cw**%U-wN2D zzUGFA8lkT^e1^gLJm-G)QiZF{furY39@?zsrh~_4}oi9i&Oh&Ug~>o{R9>c+t4^zhZm#Z6X6@3h9j zPSQ31!FQYhoFx2NaH=S94dc^bO@dE??dnVM{?5RyQTJ`gPY`;0m^k)Mfo*0j@&0@q zXCaD?ExK2W4K46s_vhfzy}7764>lM40@x{VQ2(51u$p!MCdBtwj13pT9u)i%Sc4e* z3^)$9RueVroSaj%Ti5Wo40dvHi7Q~W+crC0d>h5VZ{yhH@t56A>-U?@)>UNxt>HBb QS9?_q&fIM8bMtNaFT|~O#{d8T delta 1194 zcmYk5J8M({5QXRFX0vfk)EGB0#;9?P&uC#9L05>awRIW;1`hjX^YOkh@!*J^l*T|MJ(Ro_?P!yLtbM==cZmY3S zEdHdK8F3xK8HH%*j}`5Y73_~EI&&jW8r4@?+ei%Icd_r-C#K%P@AbHO{5H?=8}DzA zdUL<90c3Y#po>%I54<|h(NXs=CU+HEgnNVMIPo#!RyUcA1*D0a40Au@UBn&i5Qk;X zhwA1w$0o;HB^f(%@hbAVT!25E%=Oox$>woZ~r|`!xf99uqd3_2W2dk0s4A`YU zvw$Dc39vOY6@UDCB#vT=J4~F-C&6x$+n)lu(fK)S?A@rV%6Q&bEe1zu&2w1xCoZJ-P_ij mT>q=_YR2EF@p}5yyF||a>C~GimV4FJtC!v6e5W@3w)_W~E^EaA