macRes: fix OverflowError while reading resource on 32-bit Python

Fixes https://github.com/behdad/fonttools/issues/436
This commit is contained in:
Cosimo Lupo 2015-12-15 10:45:21 +00:00
parent cba2220446
commit e4ab85e90a

View File

@ -53,10 +53,16 @@ class ResourceReader(MutableMapping):
def _read(self, numBytes, offset=None):
if offset is not None:
self.file.seek(offset)
try:
self.file.seek(offset)
except OverflowError:
raise ResourceError("Failed to seek offset ('offset' is too large)")
if self.file.tell() != offset:
raise ResourceError('Failed to seek offset (reached EOF)')
data = self.file.read(numBytes)
try:
data = self.file.read(numBytes)
except OverflowError:
raise ResourceError("Cannot read resource ('numBytes' is too large)")
if len(data) != numBytes:
raise ResourceError('Cannot read resource (not enough data)')
return data