inet_pton(): Argument #1 ($ip) must not contain any null bytes

Saarbruecken

Active member
Affected version
2.3.8
I am trying to import users, nodes, threads and posts from another XF 2.3.8 forum to an existing XF 2.3.8.
However, I keep getting the error below. Any ideas?

Code:
php cmd.php xf:import
Starting import from XenForo 2.3...
 - Step 1 of 8: User groups               00:00:00 [4]
 - Step 2 of 8: Custom user fields        00:00:00 [0]
 - Step 3 of 8: Users                     00:00:00 [1]
 - Step 4 of 8: Nodes                     00:00:00 [2]
 - Step 5 of 8: Thread prefixes           00:00:00 [0]
 - Step 6 of 8: Custom thread fields      00:00:00 [0]
 - Step 7 of 8: Threads                   00:01:10 [12,841]

In Ip.php line 14:
                                                                  
  inet_pton(): Argument #1 ($ip) must not contain any null bytes
                                                                  

In Ip.php line 14:
                                                                  
  inet_pton(): Argument #1 ($ip) must not contain any null bytes 
                                                                  

xf:import [--processes PROCESSES] [--finalize]

Code:
ValueError: inet_pton(): Argument #1 ($ip) must not contain any null bytes in src/XF/Util/Ip.php at line 14

    inet_pton() in src/XF/Util/Ip.php at line 14
    XF\Util\Ip::stringToBinary() in src/XF/Import/Data/EntityEmulator.php at line 443
    XF\Import\Data\EntityEmulator->logIp() in src/XF/Import/Data/AbstractEmulatedData.php at line 93
    XF\Import\Data\AbstractEmulatedData->logIp() in src/XF/Import/Data/Post.php at line 37
    XF\Import\Data\Post->postSave() in src/XF/Import/Data/AbstractData.php at line 141
    XF\Import\Data\AbstractData->save() in src/addons/XFI/Import/Importer/XenForo2.php at line 1670
    XFI\Import\Importer\XenForo2->stepPosts() in src/XF/Import/Runner.php at line 246
    XF\Import\Runner->runStep() in src/XF/Import/Runner.php at line 61
    XF\Import\Runner->run() in src/XF/Admin/Controller/ImportController.php at line 247
    XF\Admin\Controller\ImportController->actionRun() in src/XF/Mvc/Dispatcher.php at line 362
    XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 264
    XF\Mvc\Dispatcher->dispatchFromMatch() in src/XF/Mvc/Dispatcher.php at line 121
    XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 63
    XF\Mvc\Dispatcher->run() in src/XF/App.php at line 2824
    XF\App->run() in src/XF.php at line 814
    XF::runApp() in admin.php at line 15

Code:
Server environment report
You have the recommended PHP version.

PHP version
    8.4.16

MySQL version
    11.8.3 (11.8.3-MariaDB-0+deb13u1 from Debian)

Server software
    Apache/2.4.66

PHP memory_limit
    512M

PHP post_max_size
    64M

PHP upload_max_filesize
    64M

PHP max_input_vars
    1000

PHP max_execution_time
    300

cURL version
    8.14.1

cURL SSL version
    OpenSSL/3.5.4

OpenSSL version
    OpenSSL 3.5.4 30 Sep 2025

Snuffleupagus enabled
    No

Imagick support
    Yes

EXIF support
    Yes

GZip support
    Yes

gmp support
    Yes

intl support
    No

ZipArchive support
    Yes
 
I made a bug report earlier:

You can disable Cloudflare proxy for a quick workaround while importing tho.
 
Related issue?

This is weird. A test import from XF 2.3.8 with only few threads / post was successful, however, the original XF 2.3.8 import with > 12k threads keeps throwing the error.
 
I am trying to import users, nodes, threads and posts from another XF 2.3.8 forum to an existing XF 2.3.8.
However, I keep getting the error below. Any ideas?

Code:
php cmd.php xf:import
Starting import from XenForo 2.3...
 - Step 1 of 8: User groups               00:00:00 [4]
 - Step 2 of 8: Custom user fields        00:00:00 [0]
 - Step 3 of 8: Users                     00:00:00 [1]
 - Step 4 of 8: Nodes                     00:00:00 [2]
 - Step 5 of 8: Thread prefixes           00:00:00 [0]
 - Step 6 of 8: Custom thread fields      00:00:00 [0]
 - Step 7 of 8: Threads                   00:01:10 [12,841]

In Ip.php line 14:
                                                                 
  inet_pton(): Argument #1 ($ip) must not contain any null bytes
                                                                 

In Ip.php line 14:
                                                                 
  inet_pton(): Argument #1 ($ip) must not contain any null bytes
                                                                 

xf:import [--processes PROCESSES] [--finalize]

Code:
ValueError: inet_pton(): Argument #1 ($ip) must not contain any null bytes in src/XF/Util/Ip.php at line 14

    inet_pton() in src/XF/Util/Ip.php at line 14
    XF\Util\Ip::stringToBinary() in src/XF/Import/Data/EntityEmulator.php at line 443
    XF\Import\Data\EntityEmulator->logIp() in src/XF/Import/Data/AbstractEmulatedData.php at line 93
    XF\Import\Data\AbstractEmulatedData->logIp() in src/XF/Import/Data/Post.php at line 37
    XF\Import\Data\Post->postSave() in src/XF/Import/Data/AbstractData.php at line 141
    XF\Import\Data\AbstractData->save() in src/addons/XFI/Import/Importer/XenForo2.php at line 1670
    XFI\Import\Importer\XenForo2->stepPosts() in src/XF/Import/Runner.php at line 246
    XF\Import\Runner->runStep() in src/XF/Import/Runner.php at line 61
    XF\Import\Runner->run() in src/XF/Admin/Controller/ImportController.php at line 247
    XF\Admin\Controller\ImportController->actionRun() in src/XF/Mvc/Dispatcher.php at line 362
    XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 264
    XF\Mvc\Dispatcher->dispatchFromMatch() in src/XF/Mvc/Dispatcher.php at line 121
    XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 63
    XF\Mvc\Dispatcher->run() in src/XF/App.php at line 2824
    XF\App->run() in src/XF.php at line 814
    XF::runApp() in admin.php at line 15

Code:
Server environment report
You have the recommended PHP version.

PHP version
    8.4.16

MySQL version
    11.8.3 (11.8.3-MariaDB-0+deb13u1 from Debian)

Server software
    Apache/2.4.66

PHP memory_limit
    512M

PHP post_max_size
    64M

PHP upload_max_filesize
    64M

PHP max_input_vars
    1000

PHP max_execution_time
    300

cURL version
    8.14.1

cURL SSL version
    OpenSSL/3.5.4

OpenSSL version
    OpenSSL 3.5.4 30 Sep 2025

Snuffleupagus enabled
    No

Imagick support
    Yes

EXIF support
    Yes

GZip support
    Yes

gmp support
    Yes

intl support
    No

ZipArchive support
    Yes
This error indicates that the XenForo Importer encountered corrupted or improperly formatted data while trying to process an IP address for a forum post.

Here is the breakdown of what is happening and how to fix it.

The Error in Plain English​

  • The Function: inet_pton() is a PHP function that takes a human-readable IP address (like 192.168.1.1) and converts it into a machine-readable binary format.
  • The Problem: The IP address string being passed to this function contains a "Null Byte" (\0). This is an invisible character (ASCII code 0) that often signifies the end of a string in lower-level programming but is illegal in the middle of a PHP string for this specific function.
  • The Context: You are running a XenForo 2 import (Step: Posts). One of the posts in your source database has an IP address that is likely "padded" with invisible null characters or is corrupted.

Why is this happening?​

This usually happens during database migrations or imports when:

  1. Data Corruption: The source database has a field (e.g., ip_address) that contains the IP followed by garbage characters or null padding (e.g., "127.0.0.1\0" instead of "127.0.0.1").
  2. Binary vs String Confusion: The importer might be reading a raw binary IP field from the old database but treating it as a text string, which accidentally includes null bytes.
 
  1. Data Corruption: The source database has a field (e.g., ip_address) that contains the IP followed by garbage characters or null padding (e.g., "127.0.0.1\0" instead of "127.0.0.1").
  2. Binary vs String Confusion: The importer might be reading a raw binary IP field from the old database but treating it as a text string, which accidentally includes null bytes.
And how can I figure out, which post(s) are causing the problem, so I can complete the import?
 
And how can I figure out, which post(s) are causing the problem, so I can complete the import?
  1. Open src/XF/Util/Ip.php.
  2. find convertIpStringToBinary($ip) function and replace it by the following:

Code:
public static function convertIpStringToBinary($ip)
{
    if (strpos($ip, "\0") !== false) {
        // print the hex of the bad IP 
        echo "\n[ERROR] Null byte detected in IP string. Hex: " . bin2hex($ip) . "\n";
     
        $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 10);
        foreach ($trace as $step) {
            if (isset($step['class']) && strpos($step['class'], 'StepRunner') !== false) {
                echo "Processing Step: " . $step['class'] . "\n";
            }
        }
    }

    return @inet_pton((string)$ip);
}
This will print the hex code of the bad IP right before it crashes
 
Last edited:
I don't know much about vbulletin. @MySiteGuy would be able to help you for a fee....
It's not a vBulletin forum, I am trying to import a XenForo 2.3.7 to XenForo 2.3.7.

  1. Open src/XF/Util/Ip.php.
  2. find convertIpStringToBinary($ip) function and replace it by the following:

Code:
public static function convertIpStringToBinary($ip)
{
    if (strpos($ip, "\0") !== false) {
        // This will print the Hex of the bad IP and the call stack to the console
        echo "\n[ERROR] Null byte detected in IP string. Hex: " . bin2hex($ip) . "\n";
      
        // This backtrace helps identify which record is being processed
        $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 10);
        foreach ($trace as $step) {
            if (isset($step['class']) && strpos($step['class'], 'StepRunner') !== false) {
                echo "Processing Step: " . $step['class'] . "\n";
            }
        }
    }

    return @inet_pton((string)$ip);
}
This will print the hex code of the bad IP right before it crashes
I am gonna give this a try. Thanks!
 
Unfortunately it didn't print the hex code of the bad IP address.
Is there a workaround for this, e. g. deleting all entries in xf_ip or setting all posts to the same ip address?

ValueError: inet_pton(): Argument #1 ($ip) must not contain any null bytes in src/XF/Util/Ip.php at line 14
  1. inet_pton() in src/XF/Util/Ip.php at line 14
  2. XF\Util\Ip::stringToBinary() in src/XF/Import/Data/EntityEmulator.php at line 443
  3. XF\Import\Data\EntityEmulator->logIp() in src/XF/Import/Data/AbstractEmulatedData.php at line 93
  4. XF\Import\Data\AbstractEmulatedData->logIp() in src/XF/Import/Data/Post.php at line 37
  5. XF\Import\Data\Post->postSave() in src/XF/Import/Data/AbstractData.php at line 141
  6. XF\Import\Data\AbstractData->save() in src/addons/XFI/Import/Importer/XenForo2.php at line 1670
  7. XFI\Import\Importer\XenForo2->stepPosts() in src/XF/Import/Runner.php at line 244
  8. XF\Import\Runner->runStep() in src/XF/Import/Runner.php at line 61
  9. XF\Import\Runner->run() in src/XF/Admin/Controller/ImportController.php at line 247
  10. XF\Admin\Controller\ImportController->actionRun() in src/XF/Mvc/Dispatcher.php at line 362
  11. XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 264
  12. XF\Mvc\Dispatcher->dispatchFromMatch() in src/XF/Mvc/Dispatcher.php at line 121
  13. XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 63
  14. XF\Mvc\Dispatcher->run() in src/XF/App.php at line 2824
  15. XF\App->run() in src/XF.php at line 806
  16. XF::runApp() in admin.php at line 15

Starting import from XenForo 2.3...
- Step 1 of 8: User groups 00:00:00 [4]
- Step 2 of 8: Custom user fields 00:00:00 [0]
- Step 3 of 8: Users 00:00:00 [1]
- Step 4 of 8: Nodes 00:00:00 [5]
- Step 5 of 8: Thread prefixes 00:00:00 [0]
- Step 6 of 8: Custom thread fields 00:00:00 [0]
- Step 7 of 8: Threads 00:01:13 [12,841]

In Ip.php line 14:

inet_pton(): Argument #1 ($ip) must not contain any null bytes


In Ip.php line 14:

inet_pton(): Argument #1 ($ip) must not contain any null bytes


xf:import [--processes PROCESSES] [--finalize]
 
deleting all entries in xf_ip or setting all posts to the same ip address?
Since you want only the posts ip, it would be better imo to not delete all ips from said table but only the post ips. Add a content_type = 'post' conditional for that. In doing so, all the ip data for the other actions, such as login, dms, admin login etc will remain intact. And of course, as mentioned above, make first a backup of said table before doing anything.
 
Back
Top Bottom