libwww-perl / libwww-perl/HTTP-Daemon

Missing content in new frame after \n\n. patch provided [rt.cpan.org #124327]

Open
#16 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Perl
Stars
6
Forks
17
PR merge metrics
No merged PRs in 30d

Description

Migrated from rt.cpan.org#124327 (status was 'new')

Requestors:

  • doug@jshfarms.com

From doug@jshfarms.com on 2018-02-05 16:03:58
:

If the content of a post arrives in a new frame after the double return
_sometimes_ the sysread will miss it. I don't know if this is a time
related issue or not but it happens frequently while using Axios.

To mitigate this I am checking for 'Content-Length' in the header and if it
exists, verifying that length after the double return.
The following patch implements this.

# diff -c3 /home/breshead/Downloads/Daemon.pm Daemon.pm
*** /home/breshead/Downloads/Daemon.pm 2012-02-18 04:21:23.000000000 -0800
--- Daemon.pm 2018-02-05 07:58:16.278661220 -0800
***************
*** 116,123 ****
  $buf =~ s/^(?:\015?\012)+//;  # ignore leading blank lines
  if ($buf =~ /\012/) {  # potential, has at least one line
      if ($buf =~ /^\w+[^\012]+HTTP\/\d+\.\d+\015?\012/) {
! if ($buf =~ /\015?\012\015?\012/) {
!     last READ_HEADER;  # we have it
  }
  elsif (length($buf) > 16*1024) {
      $self->send_error(413); # REQUEST_ENTITY_TOO_LARGE
--- 116,135 ----
  $buf =~ s/^(?:\015?\012)+//;  # ignore leading blank lines
  if ($buf =~ /\012/) {  # potential, has at least one line
      if ($buf =~ /^\w+[^\012]+HTTP\/\d+\.\d+\015?\012/) {
!     if ($buf =~ /\015?\012\015?\012(.*)/) {
!             # It is possible for the data to follow the double
!             # return in the next frame, especially with axios for some
reason.
!             # So if the content length exists then check it and
_need_more() as needed.
!             my $content = $1;
!             my $content_len = length($content);
!             if ($buf =~ /Content-Length:\s*(\d+)/){
!                 my $advertised_len = $1;
!                 if ($content_len >= $advertised_len){
!                     last READ_HEADER;  # we have it
!                 }
!             }else{
!                 last READ_HEADER;  # we have it
!             }
  }
  elsif (length($buf) > 16*1024) {
      $self->send_error(413); # REQUEST_ENTITY_TOO_LARGE

-- 
Doug Breshears
JSH Farms Inc.


Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in Daemon.pm at the header-reading logic around the double-return detection and compare it with the supplied patch. Reproduce a request whose body arrives in a later frame, then verify that Content-Length is honored before treating the request as complete; check any existing tests for HTTP parsing if present.

Written by the indexing model from the issue text.

Assessment

Tech stack
perl
Domain
backend, networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.