-
Notifications
You must be signed in to change notification settings - Fork 8.3k
IPv4 parsing sometimes succeeds on invalid inputs #90544
Copy link
Copy link
Closed
Description
parseIPv4SSE doesn't check that dotmask is valid (it would add noticeable overhead). Easy to find counterexamples by trying random strings consisting of '1' and '.':
SELECT
arrayStringConcat(arrayMap(i -> if((rand((number, i)) % 3) = 0, '.', '1'), range(15))) AS s,
IPv4NumToString(IPv4StringToNumOrDefault(s)) AS ip
FROM numbers(1000)
WHERE ip != '0.0.0.0'
LIMIT 10
Query id: 1249091b-2c7c-40fc-979e-2bf71ce8c01a
┌─s───────────────┬─ip───────────┐
1. │ 1111111.1111111 │ 11.11.1.1 │
2. │ 111111.111.111. │ 1.1.11.1 │
3. │ 1111111111.1.11 │ 1.1.1.11 │
4. │ 11111111.111.11 │ 11.111.1.11 │
5. │ 111.1111.111.11 │ 1.1.1.1 │
6. │ 1111111.1111111 │ 11.11.1.1 │
7. │ 1111111.1111111 │ 11.11.1.1 │
8. │ 111111111111.11 │ 11.11.111.11 │
9. │ 1.111111111.1.1 │ 1.111.11.1 │
10. │ 111.1111111.1.1 │ 111.1.11.1 │
└─────────────────┴──────────────┘Sometimes the result for one row depends on the next row:
:) select IPv4NumToString(IPv4StringToNumOrDefault(x)) from system.one array join ['24', '5.123.234'] as x
SELECT IPv4NumToString(IPv4StringToNumOrDefault(x))
FROM system.one
ARRAY JOIN ['24', '5.123.234'] AS x
Query id: 38b0f4c1-e81c-45fc-b3e9-67519fb582d0
┌─IPv4NumToStr⋯Default(x))─┐
1. │ 245.1.3.234 │
2. │ 0.0.0.0 │
└──────────────────────────┘
2 rows in set. Elapsed: 0.002 sec.
:) select IPv4NumToString(IPv4StringToNumOrDefault(x)) from system.one array join ['24'] as x
SELECT IPv4NumToString(IPv4StringToNumOrDefault(x))
FROM system.one
ARRAY JOIN ['24'] AS x
Query id: cd961c40-c679-4d3d-b3a4-69aa4c041093
┌─IPv4NumToStr⋯Default(x))─┐
1. │ 0.0.0.0 │
└──────────────────────────┘
1 row in set. Elapsed: 0.002 sec. I guess we should make it a little slower and validate the input?
(EDIT: Ok, it turned out easier to fix than expected, didn't have to create an issue.)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels