Skip to content

ext/uri: Uri\WhatWg\Url reports Ipv4OutOfRangePart with failure=true for valid integer-form IPv4 hosts #25604

Open

Description

@M4kuq

Description

Uri\WhatWg\Url::parse() accepts integer-form IPv4 hosts such as http://2130706433/ and correctly normalizes them to 127.0.0.1, but the collected validation errors still contain an Ipv4OutOfRangePart error whose $failure property is true. A validation error marked as a failure should correspond to a failed parse; here the parse succeeds and produces the correct URL.

The same happens for http://4294967295/ (255.255.255.255, the maximum valid value) and http://0x7fffffff/, while genuinely out-of-range inputs (http://4294967296/, http://256.256.256.256/) fail as expected with the same error type. No error is reported for dotted-quad input 127.0.0.1.

Root cause appears to be a combination of two components:

  1. Lexbor (vendored 2.7.0, ext/lexbor/lexbor/url/url.c): lxb_url_ipv4_append() appends an IPV4_OUT_OF_RANGE_PART log entry whenever an individual part exceeds 255 — at append time, before it is known whether that part is the last one. lxb_url_ipv4_parse() only treats an out-of-range part as an actual failure afterwards (non-final part out of range, or final part above the limit for its position). For a single-part address the parse therefore succeeds, but the log entry stays.
  2. PHP glue (ext/uri/uri_parser_whatwg.c): get_reason_from_error_type() statically maps each error type to a fixed $failure boolean, and IPV4_OUT_OF_RANGE_PART maps to true. Whether this error actually caused a failure depends on the position of the part, which a static type→bool mapping cannot express.

None of the PHP-specific Lexbor patches (ext/lexbor/patches/, 27 patches) touch this code path.

Impact: code that validates URLs by scanning $errors for any failure=true entry will wrongly reject valid URLs whose host is written in integer/hex form; and once developers notice spurious failure errors, they learn to distrust the failure flag, weakening the signal for genuine failures.

Possible fix directions (either side): in Lexbor, only log IPV4_OUT_OF_RANGE_PART once the part's position is known to make it a failure, or mark the entry non-failure at append time and upgrade it when overflow is decided; in the PHP glue, derive $failure for this type from whether parsing ultimately failed due to the IPv4 range check rather than from the type alone.

Test Script

<?php
$errors = null;
$url = Uri\WhatWg\Url::parse('http://2130706433/', null, $errors);
var_dump($url?->getAsciiHost());
foreach ($errors as $e) {
    echo $e->type->name, ' failure=', var_export($e->failure, true), PHP_EOL;
}

Expected Behaviour

Parse succeeds with host 127.0.0.1 and no failure=true validation error (the Ipv4OutOfRangePart error is either absent or reported with failure=false for a valid single-part IPv4 address).

Actual Behaviour

string(9) "127.0.0.1"
Ipv4OutOfRangePart failure=true

Full measured table (identical on PHP 8.5.12 and on master 8.7.0-dev, commit 36a9460):

Input Parse asciiHost Errors
http://2130706433/ ok 127.0.0.1 Ipv4OutOfRangePart (failure=true)
http://4294967295/ ok 255.255.255.255 Ipv4OutOfRangePart (failure=true)
http://0x7fffffff/ ok 127.255.255.255 Ipv4NonDecimalPart, Ipv4OutOfRangePart (failure=true)
http://4294967296/ fails — Ipv4OutOfRangePart (failure=true)
http://256.256.256.256/ fails — Ipv4OutOfRangePart (failure=true) ×4
http://127.0.0.1/, http://127.1/ ok 127.0.0.1 (none)

PHP Version

PHP 8.5.12, and master (PHP 8.7.0-dev, commit 36a9460)

Operating System

Linux (local CLI build, --disable-all --enable-cli)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions