quetz-mod_python-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jim Gallacher (JIRA)" <j...@apache.org>
Subject [jira] Created: (MODPYTHON-179) req.readlines(sizehint) does not work correctly
Date Sat, 08 Jul 2006 01:42:29 GMT
req.readlines(sizehint) does not work correctly
-----------------------------------------------

         Key: MODPYTHON-179
         URL: http://issues.apache.org/jira/browse/MODPYTHON-179
     Project: mod_python
        Type: Bug

  Components: core  
    Versions: 3.2.8    
 Environment: All
    Reporter: Jim Gallacher
 Assigned to: Jim Gallacher 
    Priority: Minor


A bug in req_readlines(sizehint) in requestobject.c causes output to be returned prematurely
for any value of the optional sizehint argument.

The faulty bit of code is: 

 line = req_readline(self, rlargs);
    while (line && (PyString_Size(line)>0)) {
        PyList_Append(result, line);
        size += PyString_Size(line);
        if ((sizehint != -1) && (size >= size))
            break;
         line = req_readline(self, args);
     }

Since (size >= size) will always be true, reading the input stream will end prematurely
for any value of sizehint != -1.

This code will fix the problem.

--- requestobject.c     (revision 417294)
+++ requestobject.c     (working copy)
@@ -1154,7 +1154,7 @@
     while (line && (PyString_Size(line)>0)) {
         PyList_Append(result, line);
         size += PyString_Size(line);
-        if ((sizehint != -1) && (size >= size))
+        if ((sizehint != -1) && (size >= sizehint))
             break;
         line = req_readline(self, args);
     }

Once that is fixed the documentation needs to be revised, as it does not accurately reflect
the behaviour of the code. 

Currently the docs are:
"""Reads all or up to sizehint bytes of lines using readline and returns a list of the lines
read."""

whereas the code can read beyond sizehint. The total read could actually be sizehint + len(line)
where line is the last line read.




-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


Mime
View raw message