llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

raw_fd_ostream::write_impl hang due to an infinite loop with large output

Open gbreynoo opened this issue 8 years ago • 1 comments

Bugzilla Link 37926
Resolution FIXED
Resolved on Sep 09, 2019 06:59
Version trunk
OS Windows NT
Attachments Demonstrates the hang
CC @dwblaikie
Fixed by commit(s) 339027

Extended Description

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.

gbreynoo avatar Jun 25 '18 14:06 gbreynoo

The attached script demonstrates the issue using llvm-ar

gbreynoo avatar Aug 06 '18 15:08 gbreynoo