Skip to content

Commit f73f7d4

Browse files
committed
Merge branch 'main' into 0reviews/2025/02/17/alex-kattathra-johnson/fixes-98201
2 parents 789b55d + c211040 commit f73f7d4

File tree

6 files changed

+54
-123
lines changed

6 files changed

+54
-123
lines changed

docs/changelog/122640.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 122640
2+
summary: Fix redact processor arraycopy bug
3+
area: Ingest Node
4+
type: bug
5+
issues: []

libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/entitlements/FileEntitlement.java

Lines changed: 0 additions & 43 deletions
This file was deleted.

libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/entitlements/FilesEntitlement.java

Lines changed: 23 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -41,83 +41,9 @@ public enum BaseDir {
4141

4242
public sealed interface FileData {
4343

44-
final class AbsolutePathFileData implements FileData {
45-
private final Path path;
46-
private final Mode mode;
47-
48-
private AbsolutePathFileData(Path path, Mode mode) {
49-
this.path = path;
50-
this.mode = mode;
51-
}
52-
53-
@Override
54-
public Stream<Path> resolvePaths(PathLookup pathLookup) {
55-
return Stream.of(path);
56-
}
57-
58-
@Override
59-
public Mode mode() {
60-
return mode;
61-
}
62-
63-
@Override
64-
public boolean equals(Object obj) {
65-
if (obj == this) return true;
66-
if (obj == null || obj.getClass() != this.getClass()) return false;
67-
var that = (AbsolutePathFileData) obj;
68-
return Objects.equals(this.path, that.path) && Objects.equals(this.mode, that.mode);
69-
}
70-
71-
@Override
72-
public int hashCode() {
73-
return Objects.hash(path, mode);
74-
}
75-
}
76-
77-
final class RelativePathFileData implements FileData {
78-
private final Path relativePath;
79-
private final BaseDir baseDir;
80-
private final Mode mode;
81-
82-
private RelativePathFileData(Path relativePath, BaseDir baseDir, Mode mode) {
83-
this.relativePath = relativePath;
84-
this.baseDir = baseDir;
85-
this.mode = mode;
86-
}
87-
88-
@Override
89-
public Stream<Path> resolvePaths(PathLookup pathLookup) {
90-
Objects.requireNonNull(pathLookup);
91-
switch (baseDir) {
92-
case CONFIG:
93-
return Stream.of(pathLookup.configDir().resolve(relativePath));
94-
case DATA:
95-
return Arrays.stream(pathLookup.dataDirs()).map(d -> d.resolve(relativePath));
96-
default:
97-
throw new IllegalArgumentException();
98-
}
99-
}
100-
101-
@Override
102-
public Mode mode() {
103-
return mode;
104-
}
105-
106-
@Override
107-
public boolean equals(Object obj) {
108-
if (obj == this) return true;
109-
if (obj == null || obj.getClass() != this.getClass()) return false;
110-
var that = (RelativePathFileData) obj;
111-
return Objects.equals(this.mode, that.mode)
112-
&& Objects.equals(this.relativePath, that.relativePath)
113-
&& Objects.equals(this.baseDir, that.baseDir);
114-
}
44+
Stream<Path> resolvePaths(PathLookup pathLookup);
11545

116-
@Override
117-
public int hashCode() {
118-
return Objects.hash(relativePath, baseDir, mode);
119-
}
120-
}
46+
Mode mode();
12147

12248
static FileData ofPath(Path path, Mode mode) {
12349
assert path.isAbsolute();
@@ -128,10 +54,29 @@ static FileData ofRelativePath(Path relativePath, BaseDir baseDir, Mode mode) {
12854
assert relativePath.isAbsolute() == false;
12955
return new RelativePathFileData(relativePath, baseDir, mode);
13056
}
57+
}
13158

132-
Stream<Path> resolvePaths(PathLookup pathLookup);
59+
private record AbsolutePathFileData(Path path, Mode mode) implements FileData {
60+
@Override
61+
public Stream<Path> resolvePaths(PathLookup pathLookup) {
62+
return Stream.of(path);
63+
}
64+
}
13365

134-
Mode mode();
66+
private record RelativePathFileData(Path relativePath, BaseDir baseDir, Mode mode) implements FileData {
67+
68+
@Override
69+
public Stream<Path> resolvePaths(PathLookup pathLookup) {
70+
Objects.requireNonNull(pathLookup);
71+
switch (baseDir) {
72+
case CONFIG:
73+
return Stream.of(pathLookup.configDir().resolve(relativePath));
74+
case DATA:
75+
return Arrays.stream(pathLookup.dataDirs()).map(d -> d.resolve(relativePath));
76+
default:
77+
throw new IllegalArgumentException();
78+
}
79+
}
13580
}
13681

13782
private static Mode parseMode(String mode) {

muted-tests.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,14 @@ tests:
398398
- class: org.elasticsearch.indices.recovery.IndexRecoveryIT
399399
method: testSourceThrottling
400400
issue: https://github.com/elastic/elasticsearch/issues/122712
401+
- class: org.elasticsearch.entitlement.qa.EntitlementsDeniedNonModularIT
402+
issue: https://github.com/elastic/elasticsearch/issues/122569
403+
- class: org.elasticsearch.entitlement.qa.EntitlementsAllowedNonModularIT
404+
issue: https://github.com/elastic/elasticsearch/issues/122568
405+
- class: org.elasticsearch.entitlement.qa.EntitlementsAllowedIT
406+
issue: https://github.com/elastic/elasticsearch/issues/122680
407+
- class: org.elasticsearch.entitlement.qa.EntitlementsDeniedIT
408+
issue: https://github.com/elastic/elasticsearch/issues/122566
401409

402410
# Examples:
403411
#

x-pack/plugin/redact/src/main/java/org/elasticsearch/xpack/redact/RedactProcessor.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,13 @@ public void extract(byte[] utf8Bytes, int offset, Region region) {
294294
*/
295295
String redactMatches(byte[] utf8Bytes, String redactStartToken, String redactEndToken) {
296296
var merged = mergeOverlappingReplacements(replacementPositions);
297-
int longestPatternName = merged.stream().mapToInt(r -> r.patternName.getBytes(StandardCharsets.UTF_8).length).max().getAsInt();
297+
int maxPatternNameLength = merged.stream()
298+
.mapToInt(r -> r.patternName.getBytes(StandardCharsets.UTF_8).length)
299+
.max()
300+
.getAsInt();
298301

299-
int maxPossibleLength = longestPatternName * merged.size() + utf8Bytes.length;
302+
int maxPossibleLength = (redactStartToken.length() + maxPatternNameLength + redactEndToken.length()) * merged.size()
303+
+ utf8Bytes.length;
300304
byte[] redact = new byte[maxPossibleLength];
301305

302306
int readOffset = 0;

x-pack/plugin/redact/src/test/java/org/elasticsearch/xpack/redact/RedactProcessorTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,18 @@ public void testMatchRedact() throws Exception {
108108
var redacted = RedactProcessor.matchRedact(input, List.of(grok));
109109
assertEquals("<CREDIT_CARD> <CREDIT_CARD> <CREDIT_CARD> <CREDIT_CARD>", redacted);
110110
}
111+
{
112+
var config = new HashMap<String, Object>();
113+
config.put("field", "to_redact");
114+
config.put("patterns", List.of("%{NUMBER:NUMBER}"));
115+
config.put("pattern_definitions", Map.of("NUMBER", "\\d{4}"));
116+
var processor = new RedactProcessor.Factory(mockLicenseState(), MatcherWatchdog.noop()).create(null, "t", "d", config);
117+
var grok = processor.getGroks().get(0);
118+
119+
String input = "1001";
120+
var redacted = RedactProcessor.matchRedact(input, List.of(grok), "_prefix_", "_suffix_");
121+
assertEquals("_prefix_NUMBER_suffix_", redacted);
122+
}
111123
}
112124

113125
public void testMatchRedactMultipleGroks() throws Exception {

0 commit comments

Comments
 (0)