[PATCH] D48948: Fix raw_fd_ostream::write_impl hang due to an infinite loop with large output
Owen Reynolds via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 4 10:48:41 PDT 2018
gbreynoo created this revision.
gbreynoo added reviewers: zturner, pcc.
Herald added a subscriber: llvm-commits.
On windows when raw_fd_ostream::write_impl calls write, a 32 bit input is required for character count. As a variable with size_t is used for this argument on x64 integral demotion occurs. In the case of large files an infinite loop follows.
See: https://bugs.llvm.org/show_bug.cgi?id=37926
This fix allows the output of files larger than previous int32 limit.
Repository:
rL LLVM
https://reviews.llvm.org/D48948
Files:
lib/Support/raw_ostream.cpp
Index: lib/Support/raw_ostream.cpp
===================================================================
--- lib/Support/raw_ostream.cpp
+++ lib/Support/raw_ostream.cpp
@@ -613,10 +613,15 @@
assert(FD >= 0 && "File already closed.");
pos += Size;
+#ifdef _WIN64
+ // Windows write() requires signed 32 bit input so SIZE_MAX can not be used
+ size_t MaxWriteSize = _I32_MAX;
+#else
// The maximum write size is limited to SSIZE_MAX because a write
// greater than SSIZE_MAX is implementation-defined in POSIX.
// Since SSIZE_MAX is not portable, we use SIZE_MAX >> 1 instead.
size_t MaxWriteSize = SIZE_MAX >> 1;
+#endif
#if defined(__linux__)
// It is observed that Linux returns EINVAL for a very large write (>2G).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48948.154136.patch
Type: text/x-patch
Size: 759 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180704/15d3558c/attachment.bin>
More information about the llvm-commits
mailing list