Skip to content

Commit 687cb50

Browse files
committed
Tests: fixed parsing STREAM frames split on inner frame headers.
1 parent 29a85a7 commit 687cb50

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

lib/Test/Nginx/HTTP3.pm

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -558,17 +558,28 @@ again:
558558
my $offset = 0;
559559
my ($len, $type);
560560

561-
if (!length($self->{frames_incomplete}[$stream]{buf})) {
562-
($len, $type) = parse_int(substr($buf, $offset));
563-
$offset += $len;
564-
($len, $length) = parse_int(substr($buf, $offset));
565-
$offset += $len;
561+
($len, $type) = parse_int(substr($buf, $offset));
562+
563+
if (!defined $len) {
564+
$self->{frames_incomplete}[$stream]{buf} = $buf;
565+
next;
566+
}
567+
568+
$offset += $len;
566569

567-
$self->{frames_incomplete}[$stream]{type} = $type;
568-
$self->{frames_incomplete}[$stream]{length} = $length;
569-
$self->{frames_incomplete}[$stream]{offset} = $offset;
570+
($len, $length) = parse_int(substr($buf, $offset));
571+
572+
if (!defined $len) {
573+
$self->{frames_incomplete}[$stream]{buf} = $buf;
574+
next;
570575
}
571576

577+
$offset += $len;
578+
579+
$self->{frames_incomplete}[$stream]{type} = $type;
580+
$self->{frames_incomplete}[$stream]{length} = $length;
581+
$self->{frames_incomplete}[$stream]{offset} = $offset;
582+
572583
if (length($buf) < $self->{frames_incomplete}[$stream]{length}
573584
+ $self->{frames_incomplete}[$stream]{offset})
574585
{
@@ -1987,8 +1998,12 @@ sub build_stream {
19871998

19881999
sub parse_int {
19892000
my ($buf) = @_;
2001+
return undef if length($buf) < 1;
2002+
19902003
my $val = unpack("C", substr($buf, 0, 1));
19912004
my $len = my $plen = 1 << ($val >> 6);
2005+
return undef if length($buf) < $len;
2006+
19922007
$val = $val & 0x3f;
19932008
while (--$len) {
19942009
$val = ($val << 8) + unpack("C", substr($buf, $plen - $len, 1))

0 commit comments

Comments
 (0)