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

dechunk loop can stuck on empty chunked post #7

Closed
PavelTrushkin opened this issue Jan 22, 2017 · 2 comments
Closed

dechunk loop can stuck on empty chunked post #7

PavelTrushkin opened this issue Jan 22, 2017 · 2 comments

Comments

@PavelTrushkin
Copy link

original code is
DECHUNK: while(1) {
$input->read(my $chunk, $buffer_length);

of course it will iterate forever on empty or malformed post chunked request

fix is easy
DECHUNK: while($input->read(my $chunk, $buffer_length)) {

also imho inner dechunking while is very very strange solution for potentially very large data - it copies data every $buffer_length bytes for large content

@kazeburo
Copy link
Owner

How about adding check buffer like these?

my $spin = 0;
DECHUNK: while(1) {
$input->read(my $chunk, $buffer_length);
my $read = length $chunk;
if ($read == 0 ) {
  Carp::croak "Malformed chunked request" if  $spin++ > 2000; 
  next;
}
$chunk_buffer .= $chunk;
while ( $chunk_buffer =~ s/^(([0-9a-fA-F]+).*\015\012)// ) {

@pippo
Copy link

pippo commented Jul 17, 2017

I'd like to follow up on this.
@kazeburo Can the solution above be applied?

kazeburo added a commit that referenced this issue Jul 18, 2017
Changelog diff is:

diff --git a/Changes b/Changes
index b3986c2..3d0173f 100644
--- a/Changes
+++ b/Changes
@@ -2,6 +2,11 @@ Revision history for Perl extension HTTP-Entity-Parser

 {{$NEXT}}

+0.20 2017-07-18T03:54:04Z
+
+   - [fixed] Throws exception when psgi.input is undef #6
+   - [fixed] dechunk loop can stuck on empty chunked post #7
+
 0.19 2017-02-07T08:19:45Z

    - Adjust tests for module load from a relative path when . is not in @inc (Thank you toddr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants