From: Artem Bityutskiy Date: Thu, 17 Jan 2013 09:08:01 +0000 (+0200) Subject: TransRead: fix a MemoryError issu X-Git-Tag: v2.0~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=defeb319d84b97e55c66a6c91e045d597411fadd;p=tools%2Fbmap-tools.git TransRead: fix a MemoryError issu Sometimes we run out of memory in TransRead.py, as it was reported by Dawei Wu . I believe the problem is that we read too much of compressed data at a time. If the data contain all zeroes, they are decompressed into a huge buffer. Change-Id: I4090cef33dd1afed1015bd29517ac1b8abec9ffa Signed-off-by: Artem Bityutskiy --- diff --git a/bmaptools/TransRead.py b/bmaptools/TransRead.py index 28b778d..66488a9 100644 --- a/bmaptools/TransRead.py +++ b/bmaptools/TransRead.py @@ -104,7 +104,15 @@ class _CompressedFile: # If the buffers did not contain all the requested data, read them, # decompress, and buffer. - chunk_size = max(size, 128 * 1024) + + if self._decompress_func: + # The file is compressed, in which case we should not read too much + # data at a time, because we may run out of memory when trying to + # decompress the data. + chunk_size = min(size, 128 * 1024) + else: + chunk_size = size + while size > 0: buf = self._file_obj.read(chunk_size) if not buf: