I'm sure I'm missing something, but wouldn't it be really easy to avoid this bug by not letting a user define the data length?