masks: quick fix for #9833

I still need to reconsider the logics and right places for buffer allocation
(cherry picked from commit 00ec2752bcb3a4a7e907d80d4d425e767e6d4292)