From: Artem Bityutskiy Date: Thu, 21 Feb 2013 11:06:23 +0000 (+0200) Subject: TransRead: limit the amount of bytes we read at a time X-Git-Tag: v2.5~61 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=aaea1aa1f393202fe29fb277c97e84508993b232;p=tools%2Fbmap-tools.git TransRead: limit the amount of bytes we read at a time In the function which implements fake seek forward we first calculate the amount of bytes we have to read from the file to seek forward to the requisted position, and then read that data in one go. However, the seek may be really far forward, and we'll end up reading really a lot of data in one go, which leads to high memory consumption. This patch fixes the issue by limiting the amount of data we read in one go to 1MiB. Change-Id: Idfdde2e432c216de34b4675e47c859f5e68a2928 Signed-off-by: Artem Bityutskiy --- diff --git a/bmaptools/TransRead.py b/bmaptools/TransRead.py index c19869f..37573d0 100644 --- a/bmaptools/TransRead.py +++ b/bmaptools/TransRead.py @@ -30,7 +30,8 @@ def _fake_seek_forward(file_obj, cur_pos, offset, whence = os.SEEK_SET): length = new_pos - cur_pos to_read = length while to_read > 0: - buf = file_obj.read(to_read) + chunk_size = min(to_read, 1024 * 1024) + buf = file_obj.read(chunk_size) if not buf: break to_read -= len(buf)