PNG 文件验证 [英] PNG file validation

查看:18
本文介绍了PNG 文件验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Flash 网络应用程序,可以显示用户提交的 PNG 文件.文件在显示之前通过一些 API 上传到服务器.我想确保没有坏"文件提供给 Flash,其中坏"完全不具体.有没有办法根据 PNG 规范验证 PNG 文件(这会捕获损坏的文件)?或者任何处理不受信任的图像文件的最佳实践?我只需要处理PNG,所以需要JPG、GIF等支持.语言大多无关紧要,但我更喜欢 Python 解决方案.这是在 Unix 网络服务器上.

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.

谢谢,西蒙

推荐答案

我建议你使用 Python 和 PIL(Python Imaging Library 来做到这一点):

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()

捕捉任何异常...

这篇关于PNG 文件验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆