Fix length bug in packet parsing