add safety check for bit-reading for headers
Merge pull request #323 from huili2/check_bit_read

add safety check for bit-reading for headers