Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-34226: fix cgi.parse_multipart without content_length #8530

Conversation

Roger
Copy link
Contributor

@Roger Roger commented Jul 28, 2018

In Python 3.7 the behavior of parse_multipart changed requiring CONTENT-LENGTH
header, this fix remove this header as required and fix FieldStorage
read_lines_to_outerboundary, by not using limit when it's negative,
since by default it's -1 if not content-length and keeps substracting what
was read from the file object.

Also added a test case for this problem.

https://bugs.python.org/issue34226

Automerge-Triggered-By: @orsenthil

Lib/cgi.py Outdated
@@ -717,7 +720,7 @@ def read_lines_to_outerboundary(self):
last_line_lfend = True
_read = 0
while 1:
if _read >= self.limit:
if self.limit >= 0 and _read >= self.limit:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, simplify this to:

if 0 <= self.limit <= _read

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thanks!

@Roger Roger force-pushed the fix_cgi_parse_multipart_without_content_length branch from 6275f1a to 1e085da Compare July 28, 2018 15:25
@yan12125
Copy link
Contributor

Thanks a lot for this PR! Here are my two cents:

  • Looks like a NEWS entry is necessary
  • It would be great to backport this fix to the 3.7 branch. I think that can be done by adding a needs backport to 3.7 label by a core developer?

@zooba
Copy link
Member

zooba commented Jul 29, 2018

This looks good - we just need a NEWS entry. Click on "Details" next to the failed check for info on how to install and use blurb. (The title of this PR - properly captialised - will be a fine entry, and it can go in the "Library" category.)

@Roger
Copy link
Contributor Author

Roger commented Jul 30, 2018

Should I backport to python 3.7?

@yan12125
Copy link
Contributor

Normally backporting will be carried out automatically by nice bots after the PR for master is merged :)

After the pull request has been merged, miss-islington (bot) will first try to do the backport automatically. In case that miss-islington is unable to do it, then the pull request author or the core developer who merged it should look into backporting it themselves, using the backport generated by cherry_picker.py as a starting point.

(From https://devguide.python.org/committing/#backporting-changes-to-an-older-version)

@@ -0,0 +1 @@
Fix cgi.parse_multipart without content_length
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use formatting for cgi.parse_multipart:

cgi.parse_multipart -> cgi.parse_multipart.

Also, add "Patch by Roger Duran" at the end.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, fixed

@Roger Roger force-pushed the fix_cgi_parse_multipart_without_content_length branch from 7243923 to bd4f196 Compare July 30, 2018 21:04
@@ -129,6 +129,20 @@ def test_parse_multipart(self):
'file': [b'Testing 123.\n'], 'title': ['']}
self.assertEqual(result, expected)

def test_parse_multipart_without_content_legth(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, here's a typo => test_parse_multipart_without_content_legth should be test_parse_multipart_without_content_length (missing "n")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!, fixed

@Roger Roger force-pushed the fix_cgi_parse_multipart_without_content_length branch from bd4f196 to 68e9502 Compare July 31, 2018 07:21
@yan12125
Copy link
Contributor

yan12125 commented Aug 6, 2018

@pablogsal @zooba Is there anything to do for this PR? As per PEP 537:

3.7.1: 2018-07-xx

I guess 3.7.1 is coming soon. I hope this PR can get merged before that.

@yan12125
Copy link
Contributor

The updated PEP 537 states that 3.7.1rc1 is coming the next week

  • 3.7.1 candidate 1: 2018-09-18

Can this patch be reviewed and merged before that?

@Roger
Copy link
Contributor Author

Roger commented Nov 4, 2018

Hi, just notice that this patch it's not yet merged, is there any change to be done?

@victorzhuk
Copy link

If you are waiting this PR as me, temporary solution CONTENT_LENGTH=0 python app.py or define CONTENT_LENGTH=0 env inside python script

@YtvwlD
Copy link

YtvwlD commented Aug 9, 2019

Hey, this patch is still not merged. What is missing? (This is preventing me from upgrading an app to 3.7.)

Also, the workaround CONTENT_LENGTH=0 doesn't really work for me as it creates now a different exception.

twm added a commit to twisted/twisted that referenced this pull request Dec 16, 2019
Also add a reference to python/cpython#8530
rodrigc pushed a commit to twisted/twisted that referenced this pull request Mar 28, 2020
Also add a reference to python/cpython#8530
@srinivasreddy
Copy link
Contributor

@Roger Could you please resolve conflicts?

Roger added 2 commits June 12, 2020 15:44
In Python 3.7 the behavior of parse_multipart changed requiring CONTENT-LENGTH
header, this fix remove this header as required and fix FieldStorage
read_lines_to_outerboundary, by not using limit when it's negative,
since by default it's -1 if not content-length and keeps substracting what
was read from the file object.

Also added a test case for this problem.
@Roger
Copy link
Contributor Author

Roger commented Jun 12, 2020

@Roger Could you please resolve conflicts?

sure

@Roger Roger force-pushed the fix_cgi_parse_multipart_without_content_length branch from 68e9502 to 1330f8c Compare June 12, 2020 14:53
@Roger Roger requested a review from ethanfurman as a code owner June 12, 2020 14:53
@orsenthil
Copy link
Member

I like this change. It looks like in #991 while concentrating on encoding, I missed to notice that the variable being looked for was CONTENT-LENGTH instead of CONTENT_LENGTH. Sad.

This change will address that regression introduced in 3.7. I will merge this and set the label to backport to 3.7

  • I verified the logic of this change.
  • Verified the test suite that we are good with this change.

@miss-islington
Copy link
Contributor

Thanks @Roger for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7, 3.8, 3.9.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-20890 is a backport of this pull request to the 3.9 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 15, 2020
)

In Python 3.7 the behavior of parse_multipart changed requiring CONTENT-LENGTH
header, this fix remove this header as required and fix FieldStorage
read_lines_to_outerboundary, by not using limit when it's negative,
since by default it's -1 if not content-length and keeps substracting what
was read from the file object.

Also added a test case for this problem.
(cherry picked from commit d8cf351)

Co-authored-by: roger <rogerduran@gmail.com>
@bedevere-bot
Copy link

GH-20891 is a backport of this pull request to the 3.8 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 15, 2020
)

In Python 3.7 the behavior of parse_multipart changed requiring CONTENT-LENGTH
header, this fix remove this header as required and fix FieldStorage
read_lines_to_outerboundary, by not using limit when it's negative,
since by default it's -1 if not content-length and keeps substracting what
was read from the file object.

Also added a test case for this problem.
(cherry picked from commit d8cf351)

Co-authored-by: roger <rogerduran@gmail.com>
@bedevere-bot
Copy link

GH-20892 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 15, 2020
)

In Python 3.7 the behavior of parse_multipart changed requiring CONTENT-LENGTH
header, this fix remove this header as required and fix FieldStorage
read_lines_to_outerboundary, by not using limit when it's negative,
since by default it's -1 if not content-length and keeps substracting what
was read from the file object.

Also added a test case for this problem.
(cherry picked from commit d8cf351)

Co-authored-by: roger <rogerduran@gmail.com>
miss-islington added a commit that referenced this pull request Jun 15, 2020
) (GH-20892)

In Python 3.7 the behavior of parse_multipart changed requiring CONTENT-LENGTH
header, this fix remove this header as required and fix FieldStorage
read_lines_to_outerboundary, by not using limit when it's negative,
since by default it's -1 if not content-length and keeps substracting what
was read from the file object.

Also added a test case for this problem.
(cherry picked from commit d8cf351)


Co-authored-by: roger <rogerduran@gmail.com>

Automerge-Triggered-By: @ned-deily
miss-islington added a commit that referenced this pull request Jun 15, 2020
In Python 3.7 the behavior of parse_multipart changed requiring CONTENT-LENGTH
header, this fix remove this header as required and fix FieldStorage
read_lines_to_outerboundary, by not using limit when it's negative,
since by default it's -1 if not content-length and keeps substracting what
was read from the file object.

Also added a test case for this problem.
(cherry picked from commit d8cf351)

Co-authored-by: roger <rogerduran@gmail.com>
miss-islington added a commit that referenced this pull request Jun 15, 2020
In Python 3.7 the behavior of parse_multipart changed requiring CONTENT-LENGTH
header, this fix remove this header as required and fix FieldStorage
read_lines_to_outerboundary, by not using limit when it's negative,
since by default it's -1 if not content-length and keeps substracting what
was read from the file object.

Also added a test case for this problem.
(cherry picked from commit d8cf351)

Co-authored-by: roger <rogerduran@gmail.com>
arun-mani-j pushed a commit to arun-mani-j/cpython that referenced this pull request Jul 21, 2020
)

In Python 3.7 the behavior of parse_multipart changed requiring CONTENT-LENGTH
header, this fix remove this header as required and fix FieldStorage
read_lines_to_outerboundary, by not using limit when it's negative,
since by default it's -1 if not content-length and keeps substracting what
was read from the file object.

Also added a test case for this problem.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sprint type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.