demux: add sanity checks to packet allocation functions