github-actions[bot] commented on code in PR #62906:
URL: https://github.com/apache/doris/pull/62906#discussion_r3400337618
##########
fe/fe-catalog/src/main/java/org/apache/doris/analysis/IPv4Literal.java:
##########
@@ -56,24 +60,23 @@ protected IPv4Literal(IPv4Literal other) {
this.value = other.value;
}
- private static long parseIPv4toLong(String ipv4) {
- String[] parts = ipv4.split("\\.");
- if (parts.length != 4) {
- return 0L;
+ private static long parseIPv4toLong(String ipv4) throws AnalysisException {
+ // Validate with Guava's address parser (never does DNS) instead of a
hand-rolled
+ // split, which used to accept malformed defaults such as "1.2.3.4."
(trailing dot)
+ // or "1.2.+3.4" (signed octet) and let them through at CREATE TABLE
time.
+ if (ipv4 == null || !InetAddresses.isInetAddress(ipv4)) {
+ throw new AnalysisException("Invalid IPv4 format: " + ipv4);
+ }
+ InetAddress address = InetAddresses.forString(ipv4);
+ // Guava resolves IPv4-mapped IPv6 (e.g. "::ffff:1.2.3.4") to an
Inet4Address, so also
+ // require the canonical dotted-quad form to round-trip; only real
IPv4 literals pass.
Review Comment:
This round-trip check now rejects leading-zero IPv4 defaults such as
`010.000.000.001`, even though existing Doris IPv4 semantics treat them as
valid decimal input and normalize them: the Nereids IPv4 literal regex accepts
`[01]?[0-9][0-9]?`, and the BE cast regression suite expects both normal and
strict casts of `010.000.000.001` to produce `10.0.0.1`. Because
`ColumnDef.validateDefaultValue(Type.IPV4, ...)` runs before the original
default string is persisted, `CREATE TABLE (... ip IPV4 DEFAULT
'010.000.000.001')` is now rejected while the parallel IPv4 input paths accept
the same value. This is distinct from the earlier malformed
trailing-dot/signed-octet issue; those should still be rejected, but
leading-zero octets need to remain accepted here or the parallel IPv4
semantics/tests need to be changed consistently.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]