#15018: LimitedStream.readline deals parameter not correct
-------------------------------------+--------------------------------------
          Reporter:  xjdrew          |         Owner:  nobody
            Status:  reopened        |     Milestone:        
         Component:  Core framework  |       Version:  SVN   
        Resolution:                  |      Keywords:        
             Stage:  Unreviewed      |     Has_patch:  0     
        Needs_docs:  0               |   Needs_tests:  0     
Needs_better_patch:  0               |  
-------------------------------------+--------------------------------------
Changes (by xjdrew):

  * status:  closed => reopened
  * resolution:  worksforme =>
  * component:  Uncategorized => Core framework

Comment:

 Replying to [comment:1 russellm]:
 > Your point 3 doesn't make any sense, and I can't work out what it might
 be a typo for.
 >
 > If you want to prove there is a problem here, write a formal test case.
 
[http://code.djangoproject.com/browser/django/trunk/tests/regressiontests/requests/tests.py#L101
 There are existing tests for LimitedStream] covering a wide range of
 potential use cases; if you can encode your use case as a test that fails,
 please provide that test and reopen.
 [[BR]]
 Thanks for your comment and the test case suggestion.[[BR]]
 [[BR]]
 I make a mistake about point 3, it should be:[[BR]]
 '''3. and len(self.buffer) > size'''

 I make a usecase as below:[[BR]]
 first, I modify the function LimitedStream.readline to add some log as
 below:

 {{{
 def readline(self, size=None):
         print "buff length: %s" % len(self.buffer) ####### print buffer
 size
         while '\n' not in self.buffer or \
               (size is not None and len(self.buffer) < size):
 }}}

 It will print the internal buffer status.

 second, I test the class as below:

 {{{
 >>> stream = LimitedStream(StringIO('te\nabcdefghijkhlmnopqrstuvwst'), 10)
 #### init buffer size => 10
 >>> stream.readline(5)
 buff length: 0
 'te\n'
 >>> stream.readline(1)
 buff length: 2
 'a'
 >>> stream.readline(1)
 buff length: 25  ##### buffer overflow
 'b'
 }}}


 it's easy to explain. at the beginning, the buffer size is 0, after I call
 readline(5), the buffer size becomes 2 (equals 5 - len(line) ), then I
 call readline(1), now it meets the three conditions I list before. so it
 execute '''chunk = self._read_limited(size - len(self.buffer))''', that is
 '''chunk = self._read_limited(-1)''', for the underlay StringIO, it reads
 all content. so when I call readline(1) again, you see, '''the buffer
 becomes 25, it's more than the size I init.'''

 If I replace StringIO with other stream, the behavior maybe different;
 And if the underlay stream is a very very very big file, the program maybe
 crash.
 ...

 So I suggest, it's a potential bug.

 best regards,
 Drew

-- 
Ticket URL: <http://code.djangoproject.com/ticket/15018#comment:2>
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