<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - calling string.resize(0xfffffffffffffffd) causes a segfault"
   href="https://llvm.org/bugs/show_bug.cgi?id=25358">25358</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>calling string.resize(0xfffffffffffffffd) causes a segfault
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

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

        <tr>
          <th>Hardware</th>
          <td>All
          </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>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>llvm@insonuit.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>One of our developers found that calling string.resize(0xfffffffffffffffd)
causes a segfault.

It looks like grow_by() is rounding up that size by adding 16 bytes & then
rounding down to a multiple of 16, via __recommend(); at least on this system,
which is FreeBSD x86-64 system.  That results in a zero-length allocation
request, which succeeds.

At this point, we're in trouble.  append() then calls memset, via assign(), to
zero out the 2^64 bytes or so which were added; and we crash.

Perhaps grow_by() should take alignment into account when checking whether to
throw a length error, or perhaps it needs to avoid aligning if the resulting
size will wrap around 0.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>