read(2) and thus bsdiff is limited to 2^31 bytes
Dirk Engling
erdgeist at erdgeist.org
Sun May 22 21:01:16 UTC 2016
When trying to bsdiff two DVD images, I noticed it failing due to
read(2) returning EINVAL to the tool. man 2 read says, this would only
happen for a negative value for fildes, which clearly was not true.
After more digging I found that read internally wraps a single call to
readv, preparing a temporary struct iovec. man 2 readv in turn says that
it will fail with EINVAL, if
The sum of the iov_len values in the iov array overflowed a 32-bit integer.
I saw the same behaviour on a linux system, so I kind of assume there is
a standard that allows read(2) doing that. Still I think that
1) the man page must be corrected to match this behaviour, or
2) the read(2) syscall must wrap multiple calls to readv
However, the http://www.daemonology.net/bsdiff/ page claims that:
Providing that off_t is defined properly, bsdiff and bspatch support
files of up to 2^61-1 = 2Ei-1 bytes.
which I could not confirm on any system. I could easily fix this by
using mmap instead of read to get pointers to file contents.
Now, where should I start?
erdgeist
More information about the freebsd-hackers
mailing list