Check the length of the received packet before subtracting a header/footer from it to prevent overflow. Fixes #251