Use Jon Anthony's code to get vcf header, which uses a more sensible approach, reading one line at a time until a records with # in first position is encountered.  My code was trying to calculate the number of bytes of the header by using the linear index, which turned out to by shy of the length to grab the entire header, truncating the last header record.