git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* write() _will_ fail on Mac OS X/XNU if nbytes > INT_MAX
@ 2013-04-09 22:31 Filipe Cabecinhas
  2013-04-09 22:50 ` Junio C Hamano
  0 siblings, 1 reply; 12+ messages in thread
From: Filipe Cabecinhas @ 2013-04-09 22:31 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 1500 bytes --]

Hi all,


While “git svn fetch”ing a subversion repository (private, sorry),
I've encoutered a bug that appears in several git versions (always
with the same symptoms):

git from master (from 2013-04-08)
git version 1.8.2.1 (compiled from homebrew)
git version 1.7.12.4 (Apple Git-37)

The only symptom is git blowing up with the error:
fatal: write error: Invalid argument

Problems showed up when this happened (in the SVN repo):
rev A: File F with 110K is replaced with a 9G file (don't ask…)
intermediate revs: files got added and changed, not touching file F
rev B: File F finally got reverted to the state before rev A

I can git svn fetch up to rev B-1, but svn fetching rev B will throw
the previously mentioned error.

I traced it down to write() returning <0 and setting errno to EINVAL
if nbytes > INT_MAX:
http://fxr.watson.org/fxr/source/bsd/kern/sys_generic.c?v=xnu-2050.18.24#L573
(the write() will eventually call dofilewrite, which has that check).

Testing with dd bs=INT_MAX+1 count=1 also gets me an “Invalid
argument” error, while bs=INT_MAX will do what's expected.

I have a preliminary patch that fixes it, but it may not be the
preferred way. The code is not ifdef'ed out and I'm doing the fix in
write_in_full(), while it may be preferred to do the fix in xwrite().

A radar bug has been submitted to Apple about this, but I think git
could tolerate the bug while it isn't fixed, by working around it.

Thank you,

  Filipe

[-- Attachment #2: git-darwin-bigwrites.patch --]
[-- Type: application/octet-stream, Size: 468 bytes --]

diff --git a/wrapper.c b/wrapper.c
index bac59d2..474d760 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -187,7 +187,12 @@ ssize_t write_in_full(int fd, const void *buf, size_t count)
 	ssize_t total = 0;
 
 	while (count > 0) {
-		ssize_t written = xwrite(fd, p, count);
+		ssize_t written = 0;
+        if (count >= INT_MAX)
+			written = xwrite(fd, p, INT_MAX-1);
+        else
+			written = xwrite(fd, p, count);
+
 		if (written < 0)
 			return -1;
 		if (!written) {

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2013-11-20 13:03 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-09 22:31 write() _will_ fail on Mac OS X/XNU if nbytes > INT_MAX Filipe Cabecinhas
2013-04-09 22:50 ` Junio C Hamano
2013-05-09 22:58   ` Filipe Cabecinhas
2013-05-10  2:28     ` Junio C Hamano
2013-05-10 22:24       ` Filipe Cabecinhas
2013-05-10 23:05         ` Junio C Hamano
2013-05-10 23:10           ` Junio C Hamano
2013-05-10 23:13           ` Filipe Cabecinhas
2013-05-10 23:19             ` Filipe Cabecinhas
2013-05-10 23:36               ` Junio C Hamano
2013-11-20 10:15           ` Erik Faye-Lund
2013-11-20 13:03             ` Torsten Bögershausen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).