avoid segfault on erroneous mask references (#4779)