Add packet fuzzing to the test cases. Fix various crashes exposed by this

I added a utility class (RandomPacketTest) to the test cases that does some simple packet fuzzing and then tries to construct the packets based on the fuzzed data.

This exposed a number of crashes, and this pull request fixes all of those.