Changeset 3650

Show
Ignore:
Timestamp:
26/10/08 19:18:43 (2 months ago)
Author:
dmeyer
Message:

prevent bad files from using too much IO

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/metadata/src/factory.py

    r3642 r3650  
    8787        raise core.ParseError 
    8888 
     89class File(file): 
     90 
     91    def read(self, bytes=0): 
     92        if bytes <= 0 or bytes > 1000000: 
     93            # reading more than 1MB looks like a bug 
     94            raise IOError('trying to read %s bytes' % bytes) 
     95        return super(File, self).read(bytes) 
    8996 
    9097class _Factory: 
     
    266273        if os.path.isfile(filename): 
    267274            try: 
    268                 f = open(filename,'rb') 
     275                f = File(filename,'rb') 
    269276            except (IOError, OSError), e: 
    270277                log.info('error reading %s: %s' % (filename, e))