Refactor PNGImageDecoder's call to setSize

In the existing code, if setSize fails, PNGImageDecoder attempts to
dereference the png_structp owned by m_reader. But setSize calls
setFailed on failure, deleting m_reader in the process.

As it turns out, it is unnecessary to dereference the png_structp in
this case anyway. The intent is to call longjmp in order to stop
libpng's processing, but this block of code is only executed when this
method is called directly by m_reader, so no need to longjmp.

This method, headerAvailable, is called for each frame of a PNG, but
the setup code (e.g. setSize) only needs to be done once for the entire
image. Separate the pieces that only need to be done once from
headerAvailable. This makes it more clear that there is no need to
longjmp; use a boolean return instead. Now if setSize fails, no part
of m_reader will be accessed.

Move the extra size check into a new override of setSize, and move the
color space setup code to its own method.

Add a test image that reports a size that is too big for
ImageDecoder::setSize. Attempting to decode the size should fail.

BUG=702934

Review-Url: https://codereview.chromium.org/2766263002
Cr-Commit-Position: refs/heads/master@{#459074}
5 files changed