Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PNG file validation

I have a Flash web app which displays user submitted PNG files. Files are uploaded to the server via some API prior to being displayed. I'd like to make sure no "bad" files are served to Flash, where "bad" is entirely unspecific. Is there a way to validate PNG files against the PNG specs (this would catch corrupted files)? Or any best pratice on dealing with untrusted image files? I only need to handle PNG, so JPG, GIF etc. support is necessary. Language mostly does not matter, though I'd prefer Python solutions. This is on a Unix webserver.

Thanks, Simon

like image 265
Simon Avatar asked Jan 23 '23 11:01

Simon


1 Answers

I would suggest you use Python and PIL (Python Imaging Library to do this):

from PIL import Image

v_image = Image.open(file)
v_image.verify()

Catch any exceptions...

like image 62
ChristopheD Avatar answered Jan 27 '23 18:01

ChristopheD