Fixed PHP 8.0 and 8.1 [E_WARNING] Trying to access array offset on value of type bool

masmo

Member
Xenforo version: 2.2.13 with no plugins installed and this patch
PHP version: 8.0.28 but tested also with 8.1

All Amazon link like this:
Code:
https://www.amazon.com/UPSKY-Colorful-Interactive-Physical-Exercise/dp/B07FZVML3X/ref=sr_1_6?crid=2CHY8D2JXKWRA&keywords=cat+toys&qid=1686834794&sprefix=cat%2Caps%2C178&sr=8-6

Generate an "ErrorException: [E_WARNING] Trying to access array offset on value of type bool src/XF/Util/Ip.php:340"

Code:
#0 src/XF/Util/Ip.php(340): XF::handlePhpError(2, '[E_WARNING] Try...', '/web/htdocs/www...', 340)
#1 src/XF/Http/Reader.php(368): XF\Util\Ip::ipMatchesCidrRange(false, false, 3)
#2 src/XF/Http/Reader.php(299): XF\Http\Reader->isLocalIpv6(false)
#3 src/XF/Http/Reader.php(106): XF\Http\Reader->isRequestableUntrustedUrlExtended('https://www.ama...', Array, NULL)
#4 src/XF/Http/Reader.php(81): XF\Http\Reader->requestUntrusted('get', 'https://www.ama...', Array, NULL, Array, NULL)
#5 src/XF/Http/MetadataFetcher.php(56): XF\Http\Reader->getUntrusted('https://amzn.to...', Array, NULL, Array, NULL)
#6 src/XF/Service/Unfurl/Fetcher.php(22): XF\Http\MetadataFetcher->fetch('https://amzn.to...', NULL)
#7 unfurl.php(71): XF\Service\Unfurl\Fetcher->fetch()
#8 {main}

Code:
array(4) {
  ["url"] => string(11) "/unfurl.php"
  ["referrer"] => string(57) "https://www.mysite.com/threads/php-8-0-link-amazon.8504/"
  ["_GET"] => array(0) {
  }
  ["_POST"] => array(4) {
    ["result_ids"] => array(2) {
      [0] => string(3) "553"
      [1] => string(3) "555"
    }
    ["_xfRequestUri"] => string(34) "/threads/php-8-0-link-amazon.8504/"
    ["_xfWithData"] => string(1) "1"
    ["_xfToken"] => string(8) "********"
  }
}

With PHP 7.4 it works without errors but my hosting is disabling it.
 
It doesn't seem to be caused by just amazon links, it happens with many sites as well.

The problem is very similar to this:

Maybe the thread should be moved to bug?
 
For what it's worth, I've run PHP 8.1 for quite a while and never run into this. It looks like something odd with DNS resolution. We expect any failures to simply return false, but it seems to be returning an array of records with false instead. Can you provide the output this gives you?

PHP:
<?php

$ipv6s = @dns_get_record('www.amazon.com', DNS_AAAA) ?: [];
var_dump($ipv6s);
 
Can you provide the output this gives you?

PHP 7.4.33
Code:
array(8) { [0]=> array(5) { ["host"]=> string(29) "d3ag4hukkh62yn.cloudfront.net" ["class"]=> string(2) "IN" ["ttl"]=> int(60) ["type"]=> string(4) "AAAA" ["ipv6"]=> string(36) "2600:9000:23d0:6a00:7:49a5:5fd2:8621" } [1]=> array(5) { ["host"]=> string(29) "d3ag4hukkh62yn.cloudfront.net" ["class"]=> string(2) "IN" ["ttl"]=> int(60) ["type"]=> string(4) "AAAA" ["ipv6"]=> string(36) "2600:9000:23d0:b000:7:49a5:5fd2:8621" } [2]=> array(5) { ["host"]=> string(29) "d3ag4hukkh62yn.cloudfront.net" ["class"]=> string(2) "IN" ["ttl"]=> int(60) ["type"]=> string(4) "AAAA" ["ipv6"]=> string(36) "2600:9000:23d0:f000:7:49a5:5fd2:8621" } [3]=> array(5) { ["host"]=> string(29) "d3ag4hukkh62yn.cloudfront.net" ["class"]=> string(2) "IN" ["ttl"]=> int(60) ["type"]=> string(4) "AAAA" ["ipv6"]=> string(36) "2600:9000:23d0:2a00:7:49a5:5fd2:8621" } [4]=> array(5) { ["host"]=> string(29) "d3ag4hukkh62yn.cloudfront.net" ["class"]=> string(2) "IN" ["ttl"]=> int(60) ["type"]=> string(4) "AAAA" ["ipv6"]=> string(36) "2600:9000:23d0:ea00:7:49a5:5fd2:8621" } [5]=> array(5) { ["host"]=> string(29) "d3ag4hukkh62yn.cloudfront.net" ["class"]=> string(2) "IN" ["ttl"]=> int(60) ["type"]=> string(4) "AAAA" ["ipv6"]=> string(36) "2600:9000:23d0:1200:7:49a5:5fd2:8621" } [6]=> array(5) { ["host"]=> string(29) "d3ag4hukkh62yn.cloudfront.net" ["class"]=> string(2) "IN" ["ttl"]=> int(60) ["type"]=> string(4) "AAAA" ["ipv6"]=> string(36) "2600:9000:23d0:6200:7:49a5:5fd2:8621" } [7]=> array(5) { ["host"]=> string(29) "d3ag4hukkh62yn.cloudfront.net" ["class"]=> string(2) "IN" ["ttl"]=> int(60) ["type"]=> string(4) "AAAA" ["ipv6"]=> string(36) "2600:9000:23d0:9a00:7:49a5:5fd2:8621" } }

PHP 8.0.28 and 8.1.20
Code:
array(8) { [0]=> array(5) { ["host"]=> string(29) "d3ag4hukkh62yn.cloudfront.net" ["class"]=> string(2) "IN" ["ttl"]=> int(60) ["type"]=> string(4) "AAAA" ["ipv6"]=> string(36) "2600:9000:23d0:6a00:7:49a5:5fd2:8621" } [1]=> array(5) { ["host"]=> string(29) "d3ag4hukkh62yn.cloudfront.net" ["class"]=> string(2) "IN" ["ttl"]=> int(60) ["type"]=> string(4) "AAAA" ["ipv6"]=> string(36) "2600:9000:23d0:b000:7:49a5:5fd2:8621" } [2]=> array(5) { ["host"]=> string(29) "d3ag4hukkh62yn.cloudfront.net" ["class"]=> string(2) "IN" ["ttl"]=> int(60) ["type"]=> string(4) "AAAA" ["ipv6"]=> string(36) "2600:9000:23d0:f000:7:49a5:5fd2:8621" } [3]=> array(5) { ["host"]=> string(29) "d3ag4hukkh62yn.cloudfront.net" ["class"]=> string(2) "IN" ["ttl"]=> int(60) ["type"]=> string(4) "AAAA" ["ipv6"]=> string(36) "2600:9000:23d0:2a00:7:49a5:5fd2:8621" } [4]=> array(5) { ["host"]=> string(29) "d3ag4hukkh62yn.cloudfront.net" ["class"]=> string(2) "IN" ["ttl"]=> int(60) ["type"]=> string(4) "AAAA" ["ipv6"]=> string(36) "2600:9000:23d0:ea00:7:49a5:5fd2:8621" } [5]=> array(5) { ["host"]=> string(29) "d3ag4hukkh62yn.cloudfront.net" ["class"]=> string(2) "IN" ["ttl"]=> int(60) ["type"]=> string(4) "AAAA" ["ipv6"]=> string(36) "2600:9000:23d0:1200:7:49a5:5fd2:8621" } [6]=> array(5) { ["host"]=> string(29) "d3ag4hukkh62yn.cloudfront.net" ["class"]=> string(2) "IN" ["ttl"]=> int(60) ["type"]=> string(4) "AAAA" ["ipv6"]=> string(36) "2600:9000:23d0:6200:7:49a5:5fd2:8621" } [7]=> array(5) { ["host"]=> string(29) "d3ag4hukkh62yn.cloudfront.net" ["class"]=> string(2) "IN" ["ttl"]=> int(60) ["type"]=> string(4) "AAAA" ["ipv6"]=> string(36) "2600:9000:23d0:9a00:7:49a5:5fd2:8621" } }

Looks the same...
Thanks @Jeremy P
 
Last edited:
Strange, the error implies that when the exact same code runs in the HTTP reader, some of the records have 'ipv6' => false. You can try adding this above line 299 in src/XF/Http/Reader.php:

PHP:
if ($ip === false) \XF::dumpToFile($ipv6s);

It will spit out a log file in the internal_data/temp/ directory with the unexpected data.
 
Done, Reader.php:
PHP:
$ip = $ipv6['ipv6'];
if ($ip === false) \XF::dumpToFile($ipv6s);
if ($this->isLocalIpv6($ip))

After I reproduced the error with one link there are no logs in the internal_data/temp/ directory :confused:
 
Strange. If you want to submit a ticket with server credentials I can debug this further, but short of some PHP configuration issue or JIT misbehavior I'm not sure what would cause this.
 
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.2.14).

Change log:
Properly disable outbound IPv6 requests when PHP is not compiled with IPv6 support
There may be a delay before changes are rolled out to the XenForo Community.
 
Top Bottom