Merge pull request #6305 from 10110111/dev

Fix size of TIFFTAG_EXIFIFD as passed to TIFFSetField
This commit is contained in:
Thanatomanic 2021-07-22 07:04:46 +02:00 committed by GitHub
commit d52e032af8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1399,18 +1399,19 @@ int ImageIO::saveTIFF (const Glib::ustring &fname, int bps, bool isFloat, bool u
if (exif) {
int exif_size = exif->calculateSize();
unsigned char *buffer = new unsigned char[exif_size + 8];
// TIFFOpen writes out the header and sets file pointer at position 8
const uint64_t file_offset = 8; // must be 64-bit, because TIFFTAG_EXIFIFD is
unsigned char *buffer = new unsigned char[exif_size + file_offset];
exif->write (8, buffer);
exif->write (file_offset, buffer);
write (fileno, buffer + 8, exif_size);
write (fileno, buffer + file_offset, exif_size);
delete [] buffer;
// let libtiff know that scanlines or any other following stuff should go
// at a different offset:
TIFFSetWriteOffset (out, exif_size + 8);
TIFFSetField (out, TIFFTAG_EXIFIFD, 8);
TIFFSetWriteOffset (out, exif_size + file_offset);
TIFFSetField (out, TIFFTAG_EXIFIFD, file_offset);
applyExifPatch = true;
}
}