Add missing length check

It may cause SEGV.