Skip to content

Commit

Permalink
Account for possible integer-parse exception if there are WAY too man…
Browse files Browse the repository at this point in the history
…y digits in the file-name-pattern
  • Loading branch information
TBlueF committed Jan 6, 2025
1 parent 0a1dbbe commit 91e0cdf
Showing 1 changed file with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package de.bluecolored.bluemap.core.world.mca.region;

import com.flowpowered.math.vector.Vector2i;
import de.bluecolored.bluemap.core.logger.Logger;
import de.bluecolored.bluemap.core.util.Key;
import de.bluecolored.bluemap.core.util.Keyed;
import de.bluecolored.bluemap.core.util.Registry;
Expand Down Expand Up @@ -114,16 +115,24 @@ public String getRegionFileName(int regionX, int regionZ) {
Matcher matcher = regionFileNamePattern.matcher(fileName);
if (!matcher.matches()) return null;

int regionX = Integer.parseInt(matcher.group(1));
int regionZ = Integer.parseInt(matcher.group(2));
try {

// 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;
int regionX = Integer.parseInt(matcher.group(1));
int regionZ = Integer.parseInt(matcher.group(2));

return new Vector2i(regionX, regionZ);
// 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);

} catch (NumberFormatException ex) {
return null;
}
}

}
Expand Down

0 comments on commit 91e0cdf

Please sign in to comment.