2023.04.12 15:14 "[Tiff] TIffWriteDirectory() causes problems", by David C. Partridge

2023.04.13 12:15 "Re: [Tiff] TIffWriteDirectory() causes problems", by David C. Partridge

I eventually worked out what was happening:

The very act of writing the data added two additional fields to the base IFD - specifically:

StripOffsets (3 Long): 514, 16771762, 33543010 
StripByteCounts (3 Long): 16771248, 16771248, 2496960

They were added by the libtiff code internally (not by my code).

Which meant that the base IFD was larger after writing the data than it was before. Thus, TIFFWriteDirectory over-wrote the EXIF IFD resulting in the EXIF IFD being overwritten. and the file therefore failed validation. Therefore, there's no way to avoid the base IFD being at the end of the file.