The record has a variable length. When its data is written out, the record length item indicates how many bytes to write. The last byte of data must be the last byte of an item, unless the item is a char.
Change the program so that the record length item's value points to the last byte of an item, or falls within a char item.