Fix a bug in calculating index offsets when writing database file.