开发者

PNG file validation

开发者 https://www.devze.com 2022-12-22 14:01 出处:网络
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, whe

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开发者_JAVA百科 a Unix webserver.

Thanks, Simon


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...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号