DO NOT MERGE Update libpng to 1.6.20

BUG:23265085
Change-Id: I85199805636d771f3597b691b63bc0bf46084833
(cherry picked from commit bbe98b40cda082024b669fa508931042eed18f82)

read_one_file(Image *image)
{
 if (!(image->opts & READ_FILE) || (image->opts & USE_STDIO))
 {
 /* memory or stdio. */
 FILE *f = fopen(image->file_name, "rb");

 if (f != NULL)
 {
 if (image->opts & READ_FILE)
            image->input_file = f;

 else /* memory */
 {
 if (fseek(f, 0, SEEK_END) == 0)

             {
                long int cb = ftell(f);
 
               if (cb > 0)
                {
#ifndef __COVERITY__
                  if ((unsigned long int)cb <= (size_t)~(size_t)0)
#endif
                   {
                     png_bytep b = voidcast(png_bytep, malloc((size_t)cb));
 
                     if (b != NULL)
                      {
                        rewind(f);

                        if (fread(b, (size_t)cb, 1, f) == 1)
                        {
                           fclose(f);
                           image->input_memory_size = cb;
                           image->input_memory = b;
                        }

                        else
                        {
                           free(b);
                           return logclose(image, f, image->file_name,
                              ": read failed: ");
                        }
                      }
 
                      else
                         return logclose(image, f, image->file_name,
                           ": out of memory: ");
                   }
 
                   else
                      return logclose(image, f, image->file_name,
                        ": file too big for this architecture: ");
                     /* cb is the length of the file as a (long) and
                      * this is greater than the maximum amount of
                      * memory that can be requested from malloc.
                      */
                }
 
                else if (cb == 0)
 return logclose(image, f, image->file_name,
 ": zero length: ");

 else
 return logclose(image, f, image->file_name,
 ": tell failed: ");
 }

 else
 return logclose(image, f, image->file_name, ": seek failed: ");
 }
 }

 else
 return logerror(image, image->file_name, ": open failed: ",
            strerror(errno));
 }

 return read_file(image, FORMAT_NO_CHANGE, NULL);
}

read_one_file(Image *image)
{
 if (!(image->opts & READ_FILE) || (image->opts & USE_STDIO))
 {
 /* memory or stdio. */
 FILE *f = fopen(image->file_name, "rb");

 if (f != NULL)
 {
 if (image->opts & READ_FILE)
            image->input_file = f;

 else /* memory */
 {
 if (fseek(f, 0, SEEK_END) == 0)

             {
                long int cb = ftell(f);
 
               if (cb > 0 && (unsigned long int)cb < (size_t)~(size_t)0)
                {
                  png_bytep b = voidcast(png_bytep, malloc((size_t)cb));
                  if (b != NULL)
                   {
                     rewind(f);
 
                     if (fread(b, (size_t)cb, 1, f) == 1)
                      {
                        fclose(f);
                        image->input_memory_size = cb;
                        image->input_memory = b;
                      }
 
                      else
                     {
                        free(b);
                         return logclose(image, f, image->file_name,
                           ": read failed: ");
                     }
                   }
 
                   else
                      return logclose(image, f, image->file_name,
                        ": out of memory: ");
                }
 
                else if (cb == 0)
 return logclose(image, f, image->file_name,
 ": zero length: ");

 else
 return logclose(image, f, image->file_name,
 ": tell failed: ");
 }

 else
 return logclose(image, f, image->file_name, ": seek failed: ");
 }
 }

 else
 return logerror(image, image->file_name, ": open failed: ",
            strerror(errno));
 }

 return read_file(image, FORMAT_NO_CHANGE, NULL);
}
