From d16945f30d490ee23bc06dad224c42e19ffbe856 Mon Sep 17 00:00:00 2001 From: TiM Date: Tue, 14 Apr 2026 10:42:06 +1200 Subject: [PATCH] fix(lambda): raise Jackson maxStringLength for large inline zip uploads (#412) (#418) Jackson 2.15+ defaults StreamReadConstraints.maxStringLength to 20 MB, blocking Lambda CreateFunction when the base64-encoded ZipFile exceeds that limit. AWS allows up to 50 MB direct upload (~67 MB base64). Add an ObjectMapperCustomizer that raises the limit to 100 MB, and an integration test that sends a >20 MB base64 payload to verify it works. --- .../floci/core/common/JacksonConfig.java | 25 +++++++++ .../lambda/LambdaIntegrationTest.java | 52 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 src/main/java/io/github/hectorvent/floci/core/common/JacksonConfig.java diff --git a/src/main/java/io/github/hectorvent/floci/core/common/JacksonConfig.java b/src/main/java/io/github/hectorvent/floci/core/common/JacksonConfig.java new file mode 100644 index 0000000000..13811f15ba --- /dev/null +++ b/src/main/java/io/github/hectorvent/floci/core/common/JacksonConfig.java @@ -0,0 +1,25 @@ +package io.github.hectorvent.floci.core.common; + +import com.fasterxml.jackson.core.StreamReadConstraints; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.quarkus.jackson.ObjectMapperCustomizer; +import jakarta.inject.Singleton; + +/** + * Raises this application's Jackson string-length limit so that large inline payloads + * (e.g. base64-encoded Lambda ZipFile up to ~67 MB) are accepted. + * AWS allows 50 MB direct upload; base64 expands that by ~33%. + */ +@Singleton +public class JacksonConfig implements ObjectMapperCustomizer { + + private static final int MAX_STRING_LENGTH = 100_000_000; // 100 MB + + @Override + public void customize(ObjectMapper mapper) { + mapper.getFactory().setStreamReadConstraints( + StreamReadConstraints.builder() + .maxStringLength(MAX_STRING_LENGTH) + .build()); + } +} diff --git a/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaIntegrationTest.java index d24fec0e38..dbd03d83ab 100644 --- a/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaIntegrationTest.java @@ -6,6 +6,11 @@ import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; +import java.io.ByteArrayOutputStream; +import java.util.Base64; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + import static io.restassured.RestAssured.given; import static org.hamcrest.Matchers.*; @@ -166,4 +171,51 @@ class LambdaIntegrationTest { .then() .statusCode(404); } + + @Test + @Order(11) + void createFunctionWithLargeInlineZip() throws Exception { + // Build a valid zip with a handler file + 16 MB padding so the base64 + // encoding exceeds Jackson's former 20 MB maxStringLength default. + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (ZipOutputStream zos = new ZipOutputStream(baos)) { + zos.putNextEntry(new ZipEntry("handler.py")); + zos.write("def handler(event, context): return 'ok'".getBytes()); + zos.closeEntry(); + + // 16 MB padding file using incompressible data so the zip (and its + // base64 encoding) actually exceeds Jackson's former 20 MB limit + zos.putNextEntry(new ZipEntry("padding.bin")); + byte[] chunk = new byte[1024 * 1024]; + java.util.Random rng = new java.util.Random(42); + for (int i = 0; i < 16; i++) { + rng.nextBytes(chunk); + zos.write(chunk); + } + zos.closeEntry(); + } + String base64Zip = Base64.getEncoder().encodeToString(baos.toByteArray()); + + given() + .contentType("application/json") + .body(""" + { + "FunctionName": "large-zip-fn", + "Runtime": "python3.10", + "Role": "arn:aws:iam::000000000000:role/lambda-role", + "Handler": "handler.handler", + "Code": { + "ZipFile": "%s" + } + } + """.formatted(base64Zip)) + .when() + .post(BASE_PATH + "/functions") + .then() + .statusCode(201) + .body("FunctionName", equalTo("large-zip-fn")); + + // cleanup + given().delete(BASE_PATH + "/functions/large-zip-fn"); + } }