Comment 22 for bug 1677578

On the ImageMagick Side there seems to be
  /etc/ImageMagick-6/policy.xml
Which has:
  <policy domain="resource" name="width" value="16KP"/>
That is not the case on Xenial where the rule seems to have no effect (older version).
But all that is only masking the real problem, which is why php-cgi is allowed to grow out of bounds.