@@ -502,6 +502,57 @@ public function testEndChunkWithMultipleTrailersWillBeIgnored()
502502 $ this ->input ->emit ('data ' , ["0 \r\nFoo: a \r\nBar: b \r\nBaz: c \r\n\r\n" ]);
503503 }
504504
505+ public function testEndChunkWithIncompleteTrailerWithoutCrlfWillWaitForAdditionalDataAndNotCauseInfiniteLoop ()
506+ {
507+ $ this ->parser ->on ('data ' , $ this ->expectCallableNever ());
508+ $ this ->parser ->on ('error ' , $ this ->expectCallableNever ());
509+ $ this ->parser ->on ('end ' , $ this ->expectCallableNever ());
510+ $ this ->parser ->on ('close ' , $ this ->expectCallableNever ());
511+
512+ // malformed end chunk with trailing data but without a terminating CRLF
513+ // must not loop forever, but wait for additional data
514+ $ this ->input ->emit ('data ' , ["0 \r\nab " ]);
515+ }
516+
517+ public function testEndChunkWithIncompleteTrailerWillEndOnceTrailerIsCompleted ()
518+ {
519+ $ this ->parser ->on ('data ' , $ this ->expectCallableNever ());
520+ $ this ->parser ->on ('error ' , $ this ->expectCallableNever ());
521+ $ this ->parser ->on ('end ' , $ this ->expectCallableOnce ());
522+ $ this ->parser ->on ('close ' , $ this ->expectCallableOnce ());
523+
524+ $ this ->input ->emit ('data ' , ["0 \r\nab " ]);
525+ $ this ->input ->emit ('data ' , ["\r\n\r\n" ]);
526+ }
527+
528+ public function testEndChunkWithIncompleteTrailerIsTooBig ()
529+ {
530+ $ this ->parser ->on ('data ' , $ this ->expectCallableNever ());
531+ $ this ->parser ->on ('close ' , $ this ->expectCallableOnce ());
532+ $ this ->parser ->on ('end ' , $ this ->expectCallableNever ());
533+ $ this ->parser ->on ('error ' , $ this ->expectCallableOnce ());
534+
535+ $ data = '' ;
536+ for ($ i = 0 ; $ i < 1025 ; $ i ++) {
537+ $ data .= 'a ' ;
538+ }
539+
540+ // incomplete trailer must not be buffered without any limit
541+ $ this ->input ->emit ('data ' , ["0 \r\n" . $ data ]);
542+ }
543+
544+ public function testChunkFollowedByExactlyTwoNonCrlfBytesWillErrorAndNotCauseInfiniteLoop ()
545+ {
546+ $ this ->parser ->on ('data ' , $ this ->expectCallableOnceWith ('ab ' ));
547+ $ this ->parser ->on ('error ' , $ this ->expectCallableOnce ());
548+ $ this ->parser ->on ('end ' , $ this ->expectCallableNever ());
549+ $ this ->parser ->on ('close ' , $ this ->expectCallableOnce ());
550+
551+ // completed chunk followed by exactly two bytes that are not a CRLF must not
552+ // loop forever, but report an invalid chunk terminator
553+ $ this ->input ->emit ('data ' , ["2 \r\nabXY " ]);
554+ }
555+
505556 public function testLeadingZerosInInvalidChunk ()
506557 {
507558 $ this ->parser ->on ('data ' , $ this ->expectCallableNever ());
0 commit comments