[Scipy-tickets] [SciPy] #568: scipy.io.array_import crashes when first requested line index is too high

SciPy scipy-tickets@scipy....
Tue Dec 18 12:42:55 CST 2007


#568: scipy.io.array_import crashes when first requested line index is too high
---------------------+------------------------------------------------------
 Reporter:  Gellule  |        Owner:  somebody
     Type:  defect   |       Status:  new     
 Priority:  normal   |    Milestone:  0.7     
Component:  Other    |      Version:          
 Severity:  normal   |   Resolution:          
 Keywords:           |  
---------------------+------------------------------------------------------
Comment (by Gellule):

 The following proposed patch does two things:

 @@ -149,6 +149,8 @@
 makes sure that enough lines are read to include the first requested line.

 @@ -283,7 +285,7 @@
 is a safety feature to make cases where k>K raise an exception as well,
 and not just k==K.

 -Gellule


 Index: scipy/io/array_import.py
 ===================================================================
 --- scipy/io/array_import.py    (revision 3684)
 +++ scipy/io/array_import.py    (working copy)
 @@ -149,6 +149,8 @@
          self._oldbuflines = 0
          self._linesplitter = linesep
          self._buffer = self.readlines(_READ_BUFFER_SIZE)
 +        while len(self._buffer) < self.linelist[0]:
 +            self._buffer += self.readlines(_READ_BUFFER_SIZE)
          self._totbuflines = len(self._buffer)

      def readlines(self, sizehint):
 @@ -283,7 +285,7 @@
          if firstline != '' and firstline[:lenc] != comment:
              break
          k = k + 1
 -    if k == K:
 +    if k >= K:
          raise ValueError, "First line to read not within %d lines of
 top." % K
      firstline = stream._buffer[k]
      N = len(columns)

-- 
Ticket URL: <http://scipy.org/scipy/scipy/ticket/568#comment:1>
SciPy <http://www.scipy.org/>
SciPy is open-source software for mathematics, science, and engineering.


More information about the Scipy-tickets mailing list