Code: static void perform_gamma_sbit_tests(png_modifier *pm)
{
   png_byte sbit;

 /* The only interesting cases are colour and grayscale, alpha is ignored here
    * for overall speed.  Only bit depths where sbit is less than the bit depth
    * are tested.
    */
 for (sbit=pm->sbitlow; sbit<(1<<READ_BDHI); ++sbit)
 {

       png_byte colour_type = 0, bit_depth = 0;
       unsigned int npalette = 0;
 
      while (next_format(&colour_type, &bit_depth, &npalette, 1/*gamma*/))
          if ((colour_type & PNG_COLOR_MASK_ALPHA) == 0 &&
             ((colour_type == 3 && sbit < 8) ||
             (colour_type != 3 && sbit < bit_depth)))
 {
 unsigned int i;

 for (i=0; i<pm->ngamma_tests; ++i)
 {
 unsigned int j;

 for (j=0; j<pm->ngamma_tests; ++j) if (i != j)
 {
               gamma_transform_test(pm, colour_type, bit_depth, npalette,
                  pm->interlace_type, 1/pm->gammas[i], pm->gammas[j],
                  sbit, pm->use_input_precision_sbit, 0 /*scale16*/);

 if (fail(pm))
 return;
 }
 }
 }
 }
}

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)
