#15018: LimitedStream.readline deals parameter not correct
---------------------------+------------------------------------------------
 Reporter:  xjdrew         |       Owner:  nobody    
   Status:  new            |   Milestone:            
Component:  Uncategorized  |     Version:  SVN       
 Keywords:                 |       Stage:  Unreviewed
Has_patch:  0              |  
---------------------------+------------------------------------------------
 I read the code at
 
(http://code.djangoproject.com/browser/django/trunk/django/core/handlers/wsgi.py),
 LimitedStream.readline function maybe go wrong when the situation meet
 criteria below:
 <1> '\n' not in self.buffer
 <2> and size is not None
 <3> and len(self.buffer) > len(self.buffer)
 it will go to ln102, and leads the parameter of
 LimitedStream._read_limited is negativeļ¼Œ and it will be bypassed to ln82.
 I don't read the implementation of self.stream.read, so i'm not sure if it
 will cause damage.
 Please tell me if I misunderstand the code, thanks.

 below is the code:
 {{{
 98          def readline(self, size=None):
 99              while '\n' not in self.buffer or \
 100                   (size is not None and len(self.buffer) < size):
 101                 if size:
 102                     chunk = self._read_limited(size -
 len(self.buffer))
 103                 else:
 104                     chunk = self._read_limited()
 105                 if not chunk:
 106                     break
 107                 self.buffer += chunk
 108             sio = StringIO(self.buffer)
 109             if size:
 110                 line = sio.readline(size)
 111             else:
 112                 line = sio.readline()
 113             self.buffer = sio.read()
 114             return line
 }}}


 {{{
 77          def _read_limited(self, size=None):
 78              if size is None or size > self.remaining:
 79                  size = self.remaining
 80              if size == 0:
 81                  return ''
 82              result = self.stream.read(size)
 83              self.remaining -= len(result)
 84              return result
 }}}


 best regards,
 Drew

-- 
Ticket URL: <http://code.djangoproject.com/ticket/15018>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to