Mask mode: Ensure max length is not exceeded after conversion
to UTF-8 too, if applicable. Hopefully this is the final fix
for closing #834