lionsoul2014/ip2region · error · Error
invalid ipv4 part '${ps[i]}' should >= 0 and <= 255
Error message
invalid ipv4 part '${ps[i]}' should >= 0 and <= 255 What it means
Range guard in the IPv4 parser: the octet parsed as a number but fell outside the valid 0-255 byte range (e.g. '300.1.1.1'). The message names the specific out-of-range part.
Source
Thrown at binding/javascript/util.js:66
// ---
// parse ipv4 address
function _parse_ipv4_addr(v4String) {
let ps = v4String.split('.', 4);
if (ps.length != 4) {
throw new Error('invalid ipv4 address');
}
var v;
const ipBytes = Buffer.alloc(4);
for (var i = 0; i < ps.length; i++) {
v = parseInt(ps[i], 10);
if (isNaN(v)) {
throw new Error(`invalid ipv4 part '${ps[i]}', a valid number expected`);
}
if (v < 0 || v > 255) {
throw new Error(`invalid ipv4 part '${ps[i]}' should >= 0 and <= 255`);
}
ipBytes[i] = (v & 0xFF);
}
return ipBytes;
}
// parse ipv6 address
function _parse_ipv6_addr(v6String) {
let ps = v6String.split(':', 8);
if (ps.length < 3) {
throw new Error('invalid ipv6 address');
}
let dc_num = 0, offset = 0;
const ipBytes = Buffer.alloc(16);
for (var i = 0; i < ps.length; i++) {View on GitHub (pinned to c1a1fc7d59)
Solutions
- Clamp or correct the octet so each of the four parts is between 0 and 255
- Reject inputs with any octet > 255 during upstream validation
- If the value came from a computation, mask with & 0xFF only when truncation is intended
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at binding/javascript/util.js:66 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of lionsoul2014/ip2region@c1a1fc7d59 (2026-09-02).
Data as JSON: /api/errors/266efa9bfa9e684a.
Report an issue: GitHub.