Code: set_value(png_bytep row, size_t rowbytes, png_uint_32 x, unsigned int bit_depth,
   png_uint_32 value, png_const_bytep gamma_table, double conv)
{
 unsigned int mask = (1U << bit_depth)-1;

   x *= bit_depth; /* Maximum x is 4*1024, maximum bit_depth is 16 */

 if (value <= mask)
 {
      png_uint_32 offset = x >> 3;

 if (offset < rowbytes && (bit_depth < 16 || offset+1 < rowbytes))
 {
         row += offset;

 switch (bit_depth)
 {
 case 1:
 case 2:
 case 4:
 /* Don't gamma correct - values get smashed */
 {
 unsigned int shift = (8 - bit_depth) - (x & 0x7U);

                  mask <<= shift;
                  value = (value << shift) & mask;
 *row = (png_byte)((*row & ~mask) | value);
 }
 return;

 default:
               fprintf(stderr, "makepng: bad bit depth (internal error)\n");

                exit(1);
 
             case 16:
               value = (unsigned int)floor(65535*pow(value/65535.,conv)+.5);
                *row++ = (png_byte)(value >> 8);
                *row = (png_byte)value;
                return;

 case 8:
 *row = gamma_table[value];
 return;
 }
 }

 else
 {
         fprintf(stderr, "makepng: row buffer overflow (internal error)\n");
         exit(1);
 }
 }

 else
 {
      fprintf(stderr, "makepng: component overflow (internal error)\n");
      exit(1);

    }
 }

Vulnerability Type: +Priv 
CWE ID: 
Summary: Unspecified vulnerability in libpng before 1.6.20, as used in Android 4.x before 4.4.4, 5.0.x before 5.0.2, 5.1.x before 5.1.1, and 6.x before 2016-07-01, allows attackers to gain privileges via a crafted application, as demonstrated by obtaining Signature or SignatureOrSystem access, aka internal bug 23265085.
Commit Message: DO NOT MERGE Update libpng to 1.6.20

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