Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
hollodotme committed Dec 7, 2021
2 parents af9b140 + 4556b70 commit 062182d
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .docker/php/8.1/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:8.1.0RC2-fpm-alpine
FROM php:8.1-fpm-alpine
ENV PHP_CONF_DIR=/usr/local/etc/php-fpm.d

COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
uses: mheap/phpunit-matcher-action@v1

- name: Run unit tests on PHP ${{ matrix.php }}
run: make -s "test-php-${{ matrix.php }}"
run: make -s -e "PHPUNIT_OPTIONS=--teamcity" "test-php-${{ matrix.php }}"
env:
COMPOSE_INTERACTIVE_NO_CLI: 1
PHPUNIT_OPTIONS: "--teamcity"
Expand Down
10 changes: 5 additions & 5 deletions .phive/phars.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="phpunit" version="7.5.19" installed="7.5.19" location="./.tools/phpunit-7.phar" copy="true"/>
<phar name="phpunit" version="8.5.19" installed="8.5.19" location="./.tools/phpunit-8.phar" copy="true"/>
<phar name="phpunit" version="9.5.8" installed="9.5.8" location="./.tools/phpunit-9.phar" copy="true"/>
<phar name="phpstan" version="^0.12.94" installed="0.12.99" location="./.tools/phpstan.phar" copy="true"/>
<phar name="composer" version="^2.1.5" installed="2.1.8" location="./.tools/composer.phar" copy="true"/>
<phar name="phpunit" version="7.5.20" installed="7.5.20" location="./.tools/phpunit-7.phar" copy="true"/>
<phar name="phpunit" version="8.5.21" installed="8.5.21" location="./.tools/phpunit-8.phar" copy="true"/>
<phar name="phpunit" version="9.5.10" installed="9.5.10" location="./.tools/phpunit-9.phar" copy="true"/>
<phar name="phpstan" version="^1.2.0" installed="1.2.0" location="./.tools/phpstan.phar" copy="true"/>
<phar name="composer" version="^2.1.14" installed="2.1.14" location="./.tools/composer.phar" copy="true"/>
</phive>
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file. This project adheres
to [Semantic Versioning](http://semver.org/) and [Keep a CHANGELOG](http://keepachangelog.com).

## [3.1.7] - 2021-12-07

* Make sure length values are within valid bounds

## [3.1.6] - 2021-09-23

### Added
Expand Down Expand Up @@ -410,6 +414,8 @@ on [Pierrick Charron](https://github.com/adoy)'s [PHP-FastCGI-Client](https://gi
socket connection)
* Method `Client->getValues()`

[3.1.7]: https://github.com/hollodotme/fast-cgi-client/compare/v3.1.6...v3.1.7

[3.1.6]: https://github.com/hollodotme/fast-cgi-client/compare/v3.1.5...v3.1.6

[3.1.5]: https://github.com/hollodotme/fast-cgi-client/compare/v3.1.4...v3.1.5
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ composer-update:
.PHONY: composer-update

## Run all tests on all PHP versions
tests: composer-validate phplint test-php-7.1 test-php-7.2 test-php-7.3 test-php-7.4 test-php-8.0 test-php-8.1 phpstan
tests: composer-validate phplint test-php-7.1 test-php-7.2 test-php-7.3 test-php-7.4 test-php-8.0 test-php-8.1 dcdown phpstan
.PHONY: tests

INTEGRATION_WORKER_DIR = ./tests/Integration/Workers
Expand All @@ -91,6 +91,7 @@ make-integration-workers-accessible:
.PHONY: make-integration-workers-accessible

PHP_OPTIONS = -d error_reporting=-1 -dmemory_limit=-1 -d xdebug.mode=coverage -d auto_prepend_file=tests/xdebug-filter.php
PHPUNIT_OPTIONS = --testdox

## Run PHP linting
phplint:
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ parameters:
paths:
- src
- tests
level: max
level: 8
bootstrapFiles:
- /repo/.tools/phpunit-7.phar
22 changes: 11 additions & 11 deletions src/Encoders/NameValuePairEncoder.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php declare(strict_types = 1);
<?php declare(strict_types=1);
/*
* Copyright (c) 2010-2014 Pierrick Charron
* Copyright (c) 2016-2020 Holger Woltersdorf & Contributors
Expand Down Expand Up @@ -35,7 +35,7 @@
final class NameValuePairEncoder implements EncodesNameValuePair
{
/**
* @param array<string, string> $pairs
* @param array<mixed, mixed> $pairs
*
* @return string
*/
Expand Down Expand Up @@ -105,25 +105,25 @@ public function decodePairs( string $data, int $length = -1 ) : array

while ( $p !== $length )
{
$nameLength = ord( $data[$p++] );
$nameLength = ord( $data[ $p++ ] );
if ( $nameLength >= 128 )
{
$nameLength &= (0x7F << 24);
$nameLength |= (ord( $data[$p++] ) << 16);
$nameLength |= (ord( $data[$p++] ) << 8);
$nameLength |= ord( $data[$p++] );
$nameLength |= (ord( $data[ $p++ ] ) << 16);
$nameLength |= (ord( $data[ $p++ ] ) << 8);
$nameLength |= ord( $data[ $p++ ] );
}

$valueLength = ord( $data[$p++] );
$valueLength = ord( $data[ $p++ ] );
if ( $valueLength >= 128 )
{
$valueLength = ($nameLength & 0x7F << 24);
$valueLength |= (ord( $data[$p++] ) << 16);
$valueLength |= (ord( $data[$p++] ) << 8);
$valueLength |= ord( $data[$p++] );
$valueLength |= (ord( $data[ $p++ ] ) << 16);
$valueLength |= (ord( $data[ $p++ ] ) << 8);
$valueLength |= ord( $data[ $p++ ] );
}
$array[ substr( $data, $p, $nameLength ) ] = substr( $data, $p + $nameLength, $valueLength );
$p += ($nameLength + $valueLength);
$p += ($nameLength + $valueLength);
}

return $array;
Expand Down
2 changes: 1 addition & 1 deletion src/Interfaces/EncodesNameValuePair.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
interface EncodesNameValuePair
{
/**
* @param array<string, string> $pairs
* @param array<mixed, mixed> $pairs
*
* @return string
*/
Expand Down
7 changes: 4 additions & 3 deletions src/RequestContents/JsonData.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use hollodotme\FastCGI\Interfaces\ComposesRequestContent;
use RuntimeException;
use function json_encode;
use const PHP_INT_MAX;

final class JsonData implements ComposesRequestContent
{
Expand All @@ -14,19 +15,19 @@ final class JsonData implements ComposesRequestContent
/** @var int */
private $encodingOptions;

/** @var int */
/** @var int<1, max> */
private $encodingDepth;

/**
* @param mixed $data
* @param int $options
* @param int $depth
* @param int<1, max> $depth
*/
public function __construct( $data, int $options = 0, int $depth = 512 )
{
$this->data = $data;
$this->encodingOptions = $options;
$this->encodingDepth = $depth;
$this->encodingDepth = max( 1, min( $depth, PHP_INT_MAX ) );
}

public function getContentType() : string
Expand Down
29 changes: 20 additions & 9 deletions src/Sockets/Socket.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
use function fread;
use function fwrite;
use function is_resource;
use function max;
use function microtime;
use function min;
use function ord;
use function str_repeat;
use function stream_get_meta_data;
Expand All @@ -54,14 +56,13 @@
use function stream_socket_shutdown;
use function strlen;
use function substr;
use const PHP_INT_MAX;
use const STREAM_SHUT_RDWR;

final class Socket
{
private const BEGIN_REQUEST = 1;

private const ABORT_REQUEST = 2;

private const END_REQUEST = 3;

private const PARAMS = 4;
Expand Down Expand Up @@ -314,11 +315,11 @@ private function handleFailedResource( ?int $errorNumber, ?string $errorString )
if ( null !== $lastError )
{
$lastErrorException = new ErrorException(
$lastError['message'] ?? '[No message available]',
$lastError['message'],
0,
$lastError['type'] ?? E_ERROR,
$lastError['file'] ?? '[No file available]',
$lastError['line'] ?? '[No line available]'
$lastError['type'],
$lastError['file'],
$lastError['line']
);
}

Expand Down Expand Up @@ -502,19 +503,19 @@ private function readPacket() : ?array

if ( $packet['contentLength'] )
{
$length = $packet['contentLength'];
$length = $this->getValidLength( (int)$packet['contentLength'] );

while ( $length && ($buffer = fread( $this->resource, $length )) !== false )
{
$length -= strlen( (string)$buffer );
$length = $this->getValidLength( $length - strlen( (string)$buffer ) );
$packet['content'] .= $buffer;
}
}

if ( $packet['paddingLength'] )
{
/** @noinspection UnusedFunctionResultInspection */
fread( $this->resource, (int)$packet['paddingLength'] );
fread( $this->resource, $this->getValidLength( (int)$packet['paddingLength'] ) );
}

return $packet;
Expand All @@ -523,6 +524,16 @@ private function readPacket() : ?array
return null;
}

/**
* @param int $value
*
* @return int<0, max>
*/
private function getValidLength( int $value ) : int
{
return (int)max( 0, min( $value, PHP_INT_MAX ) );
}

private function notifyPassThroughCallbacks( string $outputBuffer, string $errorBuffer ) : void
{
foreach ( $this->passThroughCallbacks as $passThroughCallback )
Expand Down

0 comments on commit 062182d

Please sign in to comment.