« Mousewheel trouble | Home | Tip of the day: Targe… »

Tip of the day: Corrupt pictures

Compared to the build in picture functions, the plugin functions in our plugins normally work better with corrupt pictures. So for example the JPEGStringToPictureMBS function can give you a picture for a corrupt JPEG or nil depending on a parameter. That's better than crashing or always returning nil.

But today I got a note that TIFFStringToPictureMBS crashes for a given tiff. The reason is that the tiff data is too short. Not even the directory does fit inside. Reading the directory structure does crash here. To solve cases like this, you can decide to add padding bytes on the end of the data. For example allocate a memoryblock with 1 few kilobytes, get a string from them and append them to the tiff data. Now if data is too short, the read will succeed and not crash. Used tags:
12 08 10 - 22:12