fix(rds-data): reject an ExecuteStatement response over 1 MiB (#5120)

* fix(rds-data): reject an ExecuteStatement response over 1 MiB

* fix(rds-data): count records array brackets and commas in the response size limit

* fix(rds-data): throw UnsupportedResultException for a response over the size limit
This commit is contained in:
Younes Beriane authored and GitHub committed 2026-10-06 14:57:29 -04:00
1 parent 45f45e590e
commit a7e2447a34
2 files changed
+52

No files matched your search

@@ -18,6 +18,7 @@ import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.jboss.logging.Logger;
import java.nio.charset.StandardCharsets;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -42,6 +43,12 @@ import java.util.concurrent.TimeUnit;
@ApplicationScoped
public class RdsDataService implements Resettable {
/**
* The Data API fails an ExecuteStatement whose response is larger than 1 MiB. Only the
* serialized records are counted; the small remainder of the body is not.
*/
private static final long MAX_RESPONSE_BYTES = 1024L * 1024L;
private static final Logger LOG = Logger.getLogger(RdsDataService.class);
/** Statement keywords whose result is a write, even when a {@code RETURNING} clause also reports rows. */
@@ -533,11 +540,18 @@ public class RdsDataService implements Resettable {
private ArrayNode records(ResultSet rs, ResultSetMetaData meta) throws SQLException {
ArrayNode records = objectMapper.createArrayNode();
int columnCount = meta.getColumnCount();
// Serialized size of the records array: its two brackets plus one comma between rows.
long responseBytes = 2;
while (rs.next()) {
ArrayNode row = objectMapper.createArrayNode();
for (int i = 1; i <= columnCount; i++) {
row.add(RdsDataFieldMapper.toField(objectMapper, rs.getObject(i), meta.getColumnType(i)));
}
responseBytes += row.toString().getBytes(StandardCharsets.UTF_8).length
+ (records.isEmpty() ? 0 : 1);
if (responseBytes > MAX_RESPONSE_BYTES) {
throw new AwsException("UnsupportedResultException", "Database response exceeded size limit", 400);
}
records.add(row);
}
return records;