facebookarchive / php-graph-sdk

The Facebook SDK for PHP provides a native interface to the Graph API and Facebook Login. https://developers.facebook.com/docs/php
Other
3.18k stars 1.96k forks source link

Undefined offset: 1 (enabled HTTP/2 support in the Curl library used by PHP) #1076

Closed izuk-langmedia closed 5 years ago

izuk-langmedia commented 6 years ago

https://github.com/facebook/php-graph-sdk/blob/3138249d85e8dc040f15bedd3581a3c616f49005/src/Facebook/Http/GraphRawResponse.php#L107

From today I am getting error like in title. I can see in logs this call:

Facebook\Http\GraphRawResponse->setHttpResponseCodeFromHeader('HTTP/2 200 ')

It doesn't match to regex in code: |HTTP/\d\.\d\s+(\d+)\s+.*|

The problem appeared after we enabled HTTP/2 support in the Curl library used by PHP.

It should be solve problem i guess: /HTTP\/\d(?:\.\d)?\s+(\d+)\s+/

Someone else getting the same error?

We are using SDK v. 5.6.3.

izuk-langmedia commented 6 years ago

I also recommend using the standard delimiter (/) instead of the one used in your code (|). It only complicates the code and makes it less universal.

bytestream commented 6 years ago

Just ran into this after libcurl was automatically updated: ea-libcurl.x86_64 0:7.61.1-1.1.1.cpanel to ea-libcurl-7.62.0-1.1.1.cpanel.x86_64

Will submit a PR.

jestinas commented 5 years ago

Dangerous programming- they are assuming that they will always get a match back from preg_match.

Atleast it should be HTTP\/\d(?:\.\d)?\s+(\d+)

jestinas commented 5 years ago

/HTTP\/\d(?:.\d)?\s+(\d+)\s+/

This won't work in this case.

HTTP/1.1 400

pako-pl commented 5 years ago

The solution in @bytestream's pull request avoids using a complicated regular expression entirely:

// https://tools.ietf.org/html/rfc7230#section-3.1.2
list($version, $status, $reason) = array_pad(explode(' ', $rawResponseHeader, 3), 3, null);
$this->httpResponseCode = (int) $status;

It also may be good to throw an exception if $status is not a valid number.

lxgiang90 commented 5 years ago

Why fix me that do not work, Please give me. Thank you. Error message: Ooophs, we got an error: Facebook Graph returned an error: The request is invalid because the app is configured as a desktop app