mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(glue): bound DeleteSchemaVersions ranges before expanding them (#3508)
A Versions expression such as 1-9223372036854775807 was expanded into a list before the 25 version limit was checked, so a single request could exhaust memory. Reject any range that would expand to more than MAX_DELETE_SCHEMA_VERSIONS entries with InvalidInputException up front, and cover the exact 25 version boundary.
This commit is contained in:
1 parent
2a4ca61baf
commit
76c1907214
2 files changed
+31
-2
No files matched your search
+10
-2
@@ -725,8 +725,16 @@ public class GlueSchemaRegistryService {
|
||||
throw new AwsException("InvalidInputException",
|
||||
"Invalid version range: " + token, 400);
|
||||
}
|
||||
for (long v = start; v <= end; v++) {
|
||||
versions.add(v);
|
||||
// Bound the range before expanding it so a request such as 1-9223372036854775807
|
||||
// is rejected outright instead of materialising every version number.
|
||||
long rangeSize = end - start;
|
||||
if (rangeSize >= MAX_DELETE_SCHEMA_VERSIONS) {
|
||||
throw new AwsException("InvalidInputException",
|
||||
"Versions expression cannot expand to more than "
|
||||
+ MAX_DELETE_SCHEMA_VERSIONS + " versions", 400);
|
||||
}
|
||||
for (long offset = 0; offset <= rangeSize; offset++) {
|
||||
versions.add(start + offset);
|
||||
}
|
||||
} else {
|
||||
versions.add(Long.parseLong(token));
|
||||
|
||||
+21
@@ -693,6 +693,27 @@ class GlueSchemaRegistryServiceTest {
|
||||
assertEquals("InvalidInputException", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteSchemaVersionsRejectsHugeRangeBeforeExpansion() {
|
||||
preCreateRegistry();
|
||||
service.createSchema(new RegistryId("reg", null), "a", "AVRO", "BACKWARD", null, AVRO_V1, null, REGION);
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class, () ->
|
||||
service.deleteSchemaVersions(new SchemaId("reg", "a", null), "1-9223372036854775807", REGION));
|
||||
|
||||
assertEquals("InvalidInputException", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteSchemaVersionsAcceptsRangeOfExactlyTwentyFiveVersions() {
|
||||
preCreateRegistry();
|
||||
service.createSchema(new RegistryId("reg", null), "a", "AVRO", "BACKWARD", null, AVRO_V1, null, REGION);
|
||||
|
||||
var results = service.deleteSchemaVersions(new SchemaId("reg", "a", null), "1-25", REGION);
|
||||
|
||||
assertEquals(25, results.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteSchemaVersionsReportsErrorsForMissingVersions() {
|
||||
preCreateRegistry();
|
||||
|
||||
Reference in new issue
Block a user