Fix crash if region map tileset file is too small

This commit is contained in:
GriffinR 2024-06-17 14:32:02 -04:00
parent 1c2be70ff0
commit 79955715dd

View file

@ -79,12 +79,17 @@ bool RegionMap::loadTilemap(poryjson::Json tilemapJson) {
this->palette_path = tilemapObject["palette"].string_value(); this->palette_path = tilemapObject["palette"].string_value();
} }
QFileInfo tilesetFileInfo(fullPath(this->tileset_path)); QImage tilesetFile(fullPath(this->tileset_path));
if (!tilesetFileInfo.exists() || !tilesetFileInfo.isFile()) { if (tilesetFile.isNull()) {
logError(QString("Failed to open region map tileset file '%1'.").arg(tileset_path)); logError(QString("Failed to open region map tileset file '%1'.").arg(tileset_path));
return false; return false;
} }
if (tilesetFile.width() < 8 || tilesetFile.height() < 8) {
logError(QString("Region map tileset file '%1' must be at least 8x8.").arg(tileset_path));
return false;
}
QFile tilemapFile(fullPath(this->tilemap_path)); QFile tilemapFile(fullPath(this->tilemap_path));
if (!tilemapFile.open(QIODevice::ReadOnly)) { if (!tilemapFile.open(QIODevice::ReadOnly)) {
logError(QString("Failed to open region map tilemap file '%1'.").arg(tilemap_path)); logError(QString("Failed to open region map tilemap file '%1'.").arg(tilemap_path));