dongxiangchan0743 2017-08-29 10:05
浏览 816

如何在php 7中处理“gd-png:致命的libpng错误:读取错误:截断的数据”

I use php 7.0.22 (Ubuntu 17.04)

When some user upload PNG with truncated data and i use:

$a = imagecreatefrompng($path);

then I get crash with:

Fatal error: imagecreatefrompng(): gd-png: fatal libpng error: Read Error: truncated data in ###.php on line ###

I try to use

try{...code...}catch(\Throwable $e){...echo...}.

and

$a = @imagecreatefrompng($path);

But script just dies with same error message. Use of imagecreatefromstring(file_get_contents($path)) has same result.

My validation of PNG: I use function getimagesize($filename) returns Array ( [0] => 1045 [1] => 734 [2] => 3 [3] => width="1045" height="734" [bits] => 8 [mime] => image/png )

How can I handle function imagecreatefrompng() or imagecreatefromstring() with truncated data PNG file?

UPD: It's a PHP7 bug on Ubuntu https://bugs.php.net/bug.php?id=73986 Bad way to make works:

$output = `php -r "imagecreatefrompng('$fname');" 2>&1`;
if (!empty($output)){
    return false; // handle error
} else {
    $result = imagecreatefrompng($fname);
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 BP神经网络控制倒立摆
    • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
    • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
    • ¥30 Unity接入微信SDK 无法开启摄像头
    • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
    • ¥20 cad图纸,chx-3六轴码垛机器人
    • ¥15 移动摄像头专网需要解vlan
    • ¥20 access多表提取相同字段数据并合并
    • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
    • ¥20 Java-Oj-桌布的计算