This commit is contained in:
Vadim Shulkin 2025-05-08 17:36:07 -04:00
parent 5b4b7f96eb
commit d6ad11e069
4 changed files with 17 additions and 12 deletions

View File

@ -27,11 +27,13 @@ import org.graylog.plugins.pipelineprocessor.ast.functions.FunctionDescriptor;
import org.graylog.plugins.pipelineprocessor.ast.functions.ParameterDescriptor; import org.graylog.plugins.pipelineprocessor.ast.functions.ParameterDescriptor;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Base64; import java.util.Base64;
import java.util.zip.GZIPInputStream; import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;
import java.net.URLDecoder; import java.net.URLDecoder;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -68,22 +70,25 @@ public class Base64InflateFunction extends AbstractFunction<String> {
final String input = inputParam.required(args, context); final String input = inputParam.required(args, context);
try { try {
LOG.debug("Received input for Base64Inflate: {}", input); LOG.debug("Received input for Base64Inflate: {}", input);
String cleanInput = URLDecoder.decode(input, StandardCharsets.UTF_8.name()); String urlDecoded = URLDecoder.decode(input, StandardCharsets.UTF_8.name());
byte[] decoded = Base64.getUrlDecoder().decode(cleanInput); byte[] base64Decoded = Base64.getDecoder().decode(urlDecoded);
try (GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(decoded))) {
byte[] uncompressed = gis.readAllBytes(); try (InflaterInputStream inflater = new InflaterInputStream(
String result = new String(uncompressed, StandardCharsets.UTF_8); new ByteArrayInputStream(base64Decoded), new Inflater(true));
LOG.debug("Decompressed result: {}", result); ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
return result;
byte[] buffer = new byte[1024];
int len;
while ((len = inflater.read(buffer)) != -1) {
outputStream.write(buffer, 0, len);
}
return outputStream.toString(StandardCharsets.UTF_8.name());
} }
} catch (Exception e) { } catch (Exception e) {
LOG.error("Base64Inflate failed: {}", e.getMessage(), e); LOG.error("Base64Inflate failed: {}", e.getMessage(), e);
return null; return null;
} }
} }
} }