Uploaded image for project: 'mod_python'
  1. mod_python
  2. MODPYTHON-179

req.readlines(sizehint) does not work correctly

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.2.8
    • Fix Version/s: 3.3.1
    • Component/s: core
    • Labels:
      None
    • Environment:
      All

      Description

      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.

        Activity

        Hide
        nlehuen Nicolas Lehuen added a comment -

        Fixed and added two unit tests on the trunk. Apply revision #420288 if this needs to be backported on the 3.2 branch.

        Show
        nlehuen Nicolas Lehuen added a comment - Fixed and added two unit tests on the trunk. Apply revision #420288 if this needs to be backported on the 3.2 branch.

          People

          • Assignee:
            jgallacher Jim Gallacher
            Reporter:
            jgallacher Jim Gallacher
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development