<html>
<head>
<base href="http://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 --- - raw_ostream.write fails to account for when buffer size is larger than INT_MAX"
href="http://llvm.org/bugs/show_bug.cgi?id=17358">17358</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>raw_ostream.write fails to account for when buffer size is larger than INT_MAX
</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>FreeBSD
</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>khilan.gudka@cl.cam.ac.uk
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Dear all
FreeBSD has a restriction that the write() system call can only write up to
INT_MAX (~2GB) bytes and will otherwise return errno 22 (EINVAL).
Adding this code to the start of write(const char *Ptr, size_t Size) in
lib/Support/raw_ostream.cpp seems to do the trick:
#ifdef __FreeBSD__
if (LLVM_UNLIKELY(Size > INT_MAX)) {
write(Ptr, INT_MAX);
return write(Ptr + INT_MAX, Size - INT_MAX);
}
#endif
I'm not sure what would be a suitable test case for this except that the
following code will tell you if your particular platform can/cannot write more
than INT_MAX:
#include <fcntl.h>
#include <errno.h>
#include <limits.h>
#define BUF_SIZE 2147483648
char arr[BUF_SIZE];
int main(int argc, char** argv) {
unsigned int i;
for (i=0; i<BUF_SIZE; i++) {
arr[i] = 3;
}
int fd = open("dump.txt", O_CREAT | O_RDWR);
int ret = write(fd, arr, BUF_SIZE);
if (ret < 0) {
printf("Error writing: %d\n", errno);
}
close(fd);
return 0;
}
Regards
Khilan</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>