Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/122640.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 122640
summary: Fix redact processor arraycopy bug
area: Ingest Node
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,13 @@ public void extract(byte[] utf8Bytes, int offset, Region region) {
*/
String redactMatches(byte[] utf8Bytes, String redactStartToken, String redactEndToken) {
var merged = mergeOverlappingReplacements(replacementPositions);
int longestPatternName = merged.stream().mapToInt(r -> r.patternName.getBytes(StandardCharsets.UTF_8).length).max().getAsInt();
int maxPatternNameLength = merged.stream()
.mapToInt(r -> r.patternName.getBytes(StandardCharsets.UTF_8).length)
.max()
.getAsInt();

int maxPossibleLength = longestPatternName * merged.size() + utf8Bytes.length;
int maxPossibleLength = (redactStartToken.length() + maxPatternNameLength + redactEndToken.length()) * merged.size()
+ utf8Bytes.length;
byte[] redact = new byte[maxPossibleLength];

int readOffset = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ public void testMatchRedact() throws Exception {
var redacted = RedactProcessor.matchRedact(input, List.of(grok));
assertEquals("<CREDIT_CARD> <CREDIT_CARD> <CREDIT_CARD> <CREDIT_CARD>", redacted);
}
{
var config = new HashMap<String, Object>();
config.put("field", "to_redact");
config.put("patterns", List.of("%{NUMBER:NUMBER}"));
config.put("pattern_definitions", Map.of("NUMBER", "\\d{4}"));
var processor = new RedactProcessor.Factory(mockLicenseState(), MatcherWatchdog.noop()).create(null, "t", "d", config);
var grok = processor.getGroks().get(0);

String input = "1001";
var redacted = RedactProcessor.matchRedact(input, List.of(grok), "_prefix_", "_suffix_");
assertEquals("_prefix_NUMBER_suffix_", redacted);
}
}

public void testMatchRedactMultipleGroks() throws Exception {
Expand Down