mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 22:37:55 -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",
|
throw new AwsException("InvalidInputException",
|
||||||
"Invalid version range: " + token, 400);
|
"Invalid version range: " + token, 400);
|
||||||
}
|
}
|
||||||
for (long v = start; v <= end; v++) {
|
// Bound the range before expanding it so a request such as 1-9223372036854775807
|
||||||
versions.add(v);
|
// 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 {
|
} else {
|
||||||
versions.add(Long.parseLong(token));
|
versions.add(Long.parseLong(token));
|
||||||
|
|||||||
+21
@@ -693,6 +693,27 @@ class GlueSchemaRegistryServiceTest {
|
|||||||
assertEquals("InvalidInputException", ex.getErrorCode());
|
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
|
@Test
|
||||||
void deleteSchemaVersionsReportsErrorsForMissingVersions() {
|
void deleteSchemaVersionsReportsErrorsForMissingVersions() {
|
||||||
preCreateRegistry();
|
preCreateRegistry();
|
||||||
|
|||||||
Reference in new issue
Block a user