I was reading this article on how to secure my website from attacker i stopped on these line and i was trying to figure out what they mean by it
you cannot rely on the file extension or the mime type to verify that the file is an image
as these can easily be faked. Even opening the file and reading the header, or using
functions to check the image size are not full proof. Most images formats allow storing a
comment section which could contain PHP code that could be executed by the server.
What do they mean by Most images formats allow storing a comment section ?
link : http://www.netmagazine.com/features/10-essential-security-tips-protect-your-site-hackers
Well, just like you can store a comment inside an MP3 file, a lot of image formats also make space for a comment. A comment is just a short bit of text to describe the file.
Lots of applications now are able to extract just a little bit of information from a lot of different file types, and the risk is that your PHP code, while extracting the comment from an image file (a relatively easy task) may run the risk of incorporating any PHP code stored in the comment into your PHP code.
Essentially, this exploited a bug in PHP, kind of similar to a SQL injection exploit. Most HTTP servers, however, when sending images, send them as binary so you needn’t worry too much about image files on web-pages being a threat.
Just make sure that any image work you do doesn’t try and interpret the comment section, instead pass it through a formatter/sanitizer to ensure that the content of an images’ comment section, if retrieved, is not just inserted into the HTML at the point of displaying it.