masks: fix buffer overflow in path shape; use dynamic instead of static buffer size