Add sanity-check for min/max expected minecraft region coordinates

This commit is contained in:
Lukas Rieger (Blue) 2025-01-06 16:29:24 +01:00
parent 77e793c958
commit 0a1dbbe3c7
No known key found for this signature in database
GPG Key ID: AA33883B1BBA03E6

View File

@ -113,10 +113,17 @@ public String getRegionFileName(int regionX, int regionZ) {
public @Nullable Vector2i getRegionFromFileName(String fileName) {
Matcher matcher = regionFileNamePattern.matcher(fileName);
if (!matcher.matches()) return null;
return new Vector2i(
Integer.parseInt(matcher.group(1)),
Integer.parseInt(matcher.group(2))
);
int regionX = Integer.parseInt(matcher.group(1));
int regionZ = Integer.parseInt(matcher.group(2));
// sanity-check for roughly minecraft max boundaries (-30 000 000 to 30 000 000)
if (
regionX < -100000 || regionX > 100000 ||
regionZ < -100000 || regionZ > 100000
) return null;
return new Vector2i(regionX, regionZ);
}
}