The only check for header validity is if it starts with the block magic bytes. This can lead to issues if a file incorrectly contains block magic bytes as padding before the first block. This type of padding is disallowed by the standard:
This empty space may be filled with any content (as long as it doesn’t contain the block_magic_token described in Blocks).
However there is no way to detect this invalid padding without reading the entire block (which might randomly be valid). Let's assume a file contains:
BLOCK_MAGIC # invalid padding
BLOCK_MAGIC # valid block magic
<block0 header>
<block0 data>
During parsing the first BLOCK_MAGIC will be found and the parser has to assume the following bytes are a header. Since the header contains no checksum of the header bytes the parser will interpret the second BLOCK_MAGIC as the first 4 bytes of the block header. If helpful I could construct a file with this invalid structure that would load incorrectly in asdf (although this would require manually editing the file as the current asdf version always pads with null bytes).
If the block header contained a checksum of header bytes parsers could:
- find BLOCK_MAGIC
- parse the header
- compare the checksum to the header bytes to validate the header
The only check for header validity is if it starts with the block magic bytes. This can lead to issues if a file incorrectly contains block magic bytes as padding before the first block. This type of padding is disallowed by the standard:
However there is no way to detect this invalid padding without reading the entire block (which might randomly be valid). Let's assume a file contains:
During parsing the first
BLOCK_MAGICwill be found and the parser has to assume the following bytes are a header. Since the header contains no checksum of the header bytes the parser will interpret the secondBLOCK_MAGICas the first 4 bytes of the block header. If helpful I could construct a file with this invalid structure that would load incorrectly in asdf (although this would require manually editing the file as the current asdf version always pads with null bytes).If the block header contained a checksum of header bytes parsers could: