<html>
    <head>
      <base href="https://bugs.freedesktop.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - NULL dereference in GfxState.cc:6127"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=101504">101504</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>NULL dereference in GfxState.cc:6127
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>poppler
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Other
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>medium
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>general
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>poppler-bugs@lists.freedesktop.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>foca@salesforce.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=132068" name="attach_132068" title="Proof of concept">attachment 132068</a> <a href="attachment.cgi?id=132068&action=edit" title="Proof of concept">[details]</a></span>
Proof of concept

There is a NULL dereference in GfxState.cc:6127.

The function drawSoftMaskedImage calls getLine() at CairoOutputDev.cc:2710
which returns NULL, and stores that in pix. The value is than passed on to the
getGrayLine function which tries to dereference it, resulting in a null
dereference. 

2708   for (y = 0; y < maskHeight; y++) {
2709     maskDest = (unsigned char *) (maskBuffer + y * row_stride);
2710     pix = maskImgStr->getLine();
2711     maskColorMap->getGrayLine (pix, maskDest, maskWidth);
2712   }

The reason NULL is returned  by getLine due to the following
`ImageStream::getLine`

 529   if (unlikely(inputLine == NULL)) {
 530       return NULL;
 531   }

At the point inp is set to whatever pix was( pix=in), in our case pix was NULL.
On line 6127 the dereference takes place and poppler crashes trying to
dereference a NULL pointer.
6123   default:
6124     inp = in;
6125     for (j = 0; j < length; j++)
6126       for (i = 0; i < nComps; i++) {
6127         *inp = byte_lookup[*inp * nComps + i];
6128         inp++;
6129       }


A solution could be an additional check at CairoOutputDev.cc:2710 to check the
line isn't NULL:
2710     pix = maskImgStr->getLine();
2711     if (pix == NULL) continue;
2712     maskColorMap->getGrayLine (pix, maskDest, maskWidth);

PoC is attached.

This vulnerability has been found by Offensive Research at Salesforce.com:
Alberto Garcia (@algillera), Francisco Oca (@francisco_oca) & Suleman Ali
(@Salbei_)</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>