summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2014-09-30 10:17:05 +0100
committerPedro Alvarez <pedro.alvarez@codethink.co.uk>2014-09-30 10:18:55 +0100
commit2f1a7002b33303fb47f5e35c2487cffe42836920 (patch)
treeeb49446f63304a2f854b84f437aed05fd6b3a9b5
parentc754d0366d4557910775bfa83c85ffdf98af0610 (diff)
downloadmorph-baserock/pedroalvarez/fix-xfer-hole.tar.gz
xfer-hole: Fix bug in copy_slice_from_file.baserock/pedroalvarez/fix-xfer-hole
os.read is limited to an int in size. copy_slice_from_file was trying to os.read more than that causing an OverflowError.
-rwxr-xr-xmorphlib/xfer-hole10
1 files changed, 8 insertions, 2 deletions
diff --git a/morphlib/xfer-hole b/morphlib/xfer-hole
index 0d4cee7a..22ee06bf 100755
--- a/morphlib/xfer-hole
+++ b/morphlib/xfer-hole
@@ -120,8 +120,14 @@ def make_xfer_instructions(fd):
def copy_slice_from_file(to, fd, start, end):
safe_lseek(fd, start, os.SEEK_SET)
- data = os.read(fd, end - start)
- to.write(data)
+ nbytes = end - start
+ max_at_a_time = 1024**2
+ while nbytes > 0:
+ data = os.read(fd, min(nbytes, max_at_a_time))
+ if not data:
+ break
+ to.write(data)
+ nbytes -= len(data)
for kind, start, end in make_xfer_instructions(fd):