AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

Thread

2020.01.13 18:22 "[Tiff] Stack corruption", by David C. Partridge
2020.01.13 18:40 "Re: [Tiff] Stack corruption", by Olivier Paquet

2020.01.13 18:22 "[Tiff] Stack corruption", by David C. Partridge

Running the following code with dwSkipExifInfo set to 0:

                if (!dwSkipExifInfo)
                {
                        // Try to read EXIF data
                        uint32                          ExifID;

                        if (TIFFGetField(m_tiff, TIFFTAG_EXIFIFD, &ExifID))
                        {
                                if (TIFFReadEXIFDirectory(m_tiff, ExifID))
                                {
                                        if (!TIFFGetField(m_tiff, EXIFTAG_EXPOSURETIME, &exposureTime))
                                                exposureTime = 0.0;
                                        if (!TIFFGetField(m_tiff, EXIFTAG_FNUMBER, &aperture))
                                                aperture = 0.0;
                                        // EXIFTAG_ISOSPEEDRATINGS is a uint16 according to the EXIF spec
                                        isospeed = 0;
                                        uint16  count = 0;
                                        uint16 * iso_setting = nullptr;
                                        if (!TIFFGetField(m_tiff, EXIFTAG_ISOSPEEDRATINGS, &count, &iso_setting))
                                                isospeed = 0;
                                        else
                                        {
                                                isospeed = iso_setting[0];
                                        }
                                        // EXIFTAG_GAINCONTROL does not represent a gain value, so ignore it.
                                };
                        };
                           }
                else
                {
                        CBitmapInfo                     BitmapInfo;

                        if (RetrieveEXIFInfo(m_strFileName, BitmapInfo))
                        {
                                exposureTime = BitmapInfo.m_fExposure;
                                aperture         = BitmapInfo.m_fAperture;
                                isospeed         = BitmapInfo.m_lISOSpeed;
                                gain             = BitmapInfo.m_lGain;
                                m_DateTime       = BitmapInfo.m_DateTime;
                        };
                };

                // Retrieve the Date/Time as in the TIFF TAG
                char *                          szDateTime;

                if (TIFFGetField(m_tiff, TIFFTAG_DATETIME, &szDateTime))
                {
                        CString                 strDateTime = szDateTime;

                        // Decode 2007:11:02 22:07:03
                        //        0123456789012345678

                        if (strDateTime.GetLength() >= 19)
                        {
                                m_DateTime.wYear  = _ttol(strDateTime.Left(4));
                                m_DateTime.wMonth = _ttol(strDateTime.Mid(5, 2));
                                m_DateTime.wDay   = _ttol(strDateTime.Mid(8, 2));
                                m_DateTime.wHour  = _ttol(strDateTime.Mid(11, 2));
                                m_DateTime.wMinute= _ttol(strDateTime.Mid(14, 2));
                                m_DateTime.wSecond= _ttol(strDateTime.Mid(17, 2));
                        };
                };

                if (bResult)
                        bResult = OnOpen();
                if (!bResult)
                {
                        TIFFClose(m_tiff);
                        m_tiff = nullptr;
                };
        };

        return bResult;
};

On exit from the function, I get warning of Stack Corruption around variable ExifID!

What did I do wrong here?

David