The other special size value is 0, which means "this box runs to the end of the file." Today you resolve that case using the total buffer length, so the last box in a file always has a concrete size.
When the size field is 0, set the box size to reach the end of the buffer.
A size field of 0 means the box extends to the end of the file - it is the
last box, and rather than store its length up front the writer just lets it run
out. To resolve it you need to know where the enclosing buffer ends: the box’s true
size is total - offset, where offset is where this box began. In a 24-byte
buffer a size-0 box at offset 0 is 24 bytes; drop the same bytes into a 40-byte
buffer and it is 40.
This is why parsing needs to carry an offset and a total alongside the bytes.
With the normal form, the largesize form, and now the to-end-of-file form all
handled, your header parser is complete. Tomorrow you read the first real box’s
payload.
// size 0 means "to the end of the enclosing buffer"func parseHeaderAt(b []byte, offset int, total int) Box {// parse as before, but if the size field is 0,// set size = total - offset// (fill in)}