title: imagecreatefrompng (and imagecreatefromstring) causes to unrecoverable fatal error
body: <p>When I'm trying use php-gd functions on incorrect png images, I have Fatal PHP error. It seems to be some kind of bug, because accordingly to the functions documentation (<code>imagecreatefrompng</code>, for example):</p>
  
  <p><code>* @return resource an image resource identifier on success, false on errors.</code></p>
  
  <p>But when I try to do it with my incorrect image, I have:</p>
  
  <p><code>Fatal error:  imagecreatefrompng(): gd-png: fatal libpng error: Read Error: truncated data in /var/www/common/models/Utils.php on line 61
  </code></p>
  
  <p>The code that leads to this error is simple:</p>
  
  <pre><code>$handle = imagecreatefrompng($fname);
  </code></pre>
  
  <p>No code executes after this string.</p>
  
  <p>The same behaviour is for <code>imagecreatefromstring</code> when trying to create an image from the same string.</p>
  
  <p>I can't "fix" this picture, because it is user-provided, so I need to handle this cases.</p>
  
  <p>I tried to use <code>try...catch</code> block like this:</p>
  
  <pre><code>echo 'start'."\n";
  try {
      imagecreatefromstring($result);
  } catch (\Throwable $e) {
      echo 'error'."\n";
      return null;
  }
  echo 'success'."\n";
  </code></pre>
  
  <p>But script outputs only "start", and then dies and shows error description I have posted above.</p>
  
  <p>Ubuntu 16.04.2, PHP 7.0, php7.0-gd extension, both are latest version.</p>
  
  <p>So I can't handle it with try...catch block and I don't know how to handle or fix it at all. Any ideas?</p>
  
  <p><strong>UPD:</strong> It seems to be really weird bug with environment, because when I run same code under Windows (with PHP 7.0) it produces correct "Warning" error.</p>
  
  <p><strong>UPD2:</strong> It seems to be that fresh bug <a href="https://bugs.php.net/bug.php?id=73986" rel="noreferrer">https://bugs.php.net/bug.php?id=73986</a></p>