<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 - Broken pdf/ps output due to badly placed newline"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=100029">100029</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Broken pdf/ps output due to badly placed newline
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>cairo
          </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>pdf backend
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>ajohnson@redneon.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>jmmorlan@sonic.net
          </td>
        </tr>

        <tr>
          <th>QA Contact</th>
          <td>cairo-bugs@cairographics.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=130021" name="attach_130021" title="Patch">attachment 130021</a> <a href="attachment.cgi?id=130021&action=edit" title="Patch">[details]</a></span> <a href='page.cgi?id=splinter.html&bug=100029&attachment=130021'>[review]</a>
Patch

In src/cairo-pdf-operators.c, _word_wrap_stream_write might insert a newline
into the output of _cairo_pdf_operators_emit_glyph_string_with_positioning in
the middle of an escape sequence and result in a broken PDF (or PS) file.

The code responsible for this:

    if (*data == '\n' || stream->column >= stream->max_column) {
        _cairo_output_stream_printf (stream->output, "\n");
        stream->column = 0;
    } else if (*data == '<') {
        stream->state = WRAP_STATE_HEXSTRING;
    } else if (*data == '(') {
        stream->state = WRAP_STATE_STRING;
    } else if (!_cairo_isspace (*data)) {
        stream->state = WRAP_STATE_WORD;
    }

When the "stream->column >= stream->max_column" case is hit, stream->state
doesn't get updated.

Here's a (simplified, purged of private information) example of how this can be
a problem:

[......................................................................27
(<)................................................................-713(\
()...]TJ

After "27(", the state didn't get changed to WRAP_STATE_STRING, so it got
incorrectly set to WRAP_STATE_HEXSTRING after the "<". The rest of the sequence
was wrapped with hex-string rules, and a newline was put in "-713(\()" exactly
where it shouldn't be.</pre>
        </div>
      </p>


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

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