Skip to content

Commit 73f7594

Browse files
authored
ESQL: No, line noise isn't a valid ip (#127527) (#127539)
I wrote an `&&` when I meant and `||` in #126338 and that caused some impressive looking line noise to parse as valid ipv4 addresses. Randomized tests caught it eventually.
1 parent 71a6c7f commit 73f7594

File tree

3 files changed

+24
-2
lines changed
  • docs/changelog
  • x-pack/plugin/esql/src
    • main/java/org/elasticsearch/xpack/esql/expression/function/scalar/convert
    • test/java/org/elasticsearch/xpack/esql/expression/function/scalar/convert

3 files changed

+24
-2
lines changed

docs/changelog/127527.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 127527
2+
summary: "No, line noise isn't a valid ip"
3+
area: ES|QL
4+
type: bug
5+
issues: []

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/convert/ParseIp.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,14 @@ public static BytesRef leadingZerosAreOctal(
204204
}
205205

206206
private static int digit(BytesRef string, int offset) {
207-
if (string.bytes[offset] < '0' && '9' < string.bytes[offset]) {
207+
if (string.bytes[offset] < '0' || '9' < string.bytes[offset]) {
208208
throw invalid(string);
209209
}
210210
return string.bytes[offset] - '0';
211211
}
212212

213213
private static int octalDigit(BytesRef string, int offset) {
214-
if (string.bytes[offset] < '0' && '7' < string.bytes[offset]) {
214+
if (string.bytes[offset] < '0' || '7' < string.bytes[offset]) {
215215
throw invalid(string);
216216
}
217217
return string.bytes[offset] - '0';

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/convert/ParseIpTests.java

+17
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,23 @@ public static Iterable<Object[]> parameters() {
4343
new TestCase("255.0", false, false, false),
4444
new TestCase("255.255.1", false, false, false),
4545
new TestCase("255.255.0", false, false, false),
46+
new TestCase("a.a.a.a", false, false, false),
47+
new TestCase(
48+
/*
49+
* At some point the ip parsing code parsed this as a valid ipv4 address. Use git-blame if you
50+
* are curious. It was a dark time.
51+
*/
52+
"\u0007I\u001B|R\u0017t)Q W+\u001F5\n"
53+
+ "(\u001E~H@u9Sbc~2\u000BH=\tNZ_vSUnv/GL=5Ag2n\u0012 P\u0007?dyA,=~F!\u001C0\fQ\u0011\u0012.5<yR <I;rU\u001A"
54+
+ "\u001Av4(\u0014q{\u0018\u001FE\u000B1T8N\\\u0015\u000F\n"
55+
+ "N3T(\n"
56+
+ "\u000B,\u0017)_r\u007F*1\u0018`T\"0%hlvBsOkKeb+.b6\u001Bz5\"U\u000Fe\u0019).\u0003XArg\u001E\fWxbF\u0001\u0015"
57+
+ "%(JQ_]\u001Aw'#vD\tW\u0016w)mNx&\u001E\u001B\u0007\u000FPf5Hw\u0004\u0015\u0015\\\u007FG\"~XJ\u0006"
58+
+ "aE\u0018}Y9\u001C\u0018a",
59+
false,
60+
false,
61+
false
62+
),
4663
new TestCase(new Supplier<>() {
4764
@Override
4865
public String get() {

0 commit comments

Comments
 (0)