Fix another possible NULL deref.
Tighten up packet entity parsing & emission.

This fixes a theoretical NULL dereference and some theoretical OOB accesses.