<html>
    <head>
      <base href="https://bugs.llvm.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 - raw_fd_ostream::write_impl hang due to an infinite loop with large output"
   href="https://bugs.llvm.org/show_bug.cgi?id=37926">37926</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>raw_fd_ostream::write_impl  hang due to an infinite loop with large output
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </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>Support Libraries
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>gbreynoo@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The Windows implementation of raw_fd_ostream::write_impl calls Windows write:

write(int _FileHandle, void const* _Buf, unsigned int _MaxCharCount)

ChunkSize is a size_t type (unsigned 64bit on x64) used for the argument
_MaxCharCount (unsigned 32bit). This means there is an integral demotion and
only the least significant bytes are retained. 

In the case of ChunkSize over 2^32 the least significant bytes are used and the
write performs successfully. Ptr and buffer size are then modified to reflect
this write, meaning the next ChunkSize will be a 64bit value with the least
significant bytes equalling 0.

When _MaxCharCount equals 0 Windows write fails, but as this is a recoverable
error  raw_fd_ostream::write_impl reattempts the write. The program is now
caught in an infinite loop.

This was seen on Windows 10 using Visual Studio 2015, x64 build.</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>