From 3a5bd83ebae5bb4a3536e1af1d117bff2db61073 Mon Sep 17 00:00:00 2001 From: cflip Date: Wed, 23 Mar 2022 18:00:54 -0600 Subject: Prevent oversized levels from saving The current level format uses bytes to store the width and height, so levels that are larger than that are not allowed to be saved. I don't think that the game will need levels larger than 255x255, but if it does then the level format can be updated. --- src/level.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/level.cpp b/src/level.cpp index 5fa4619..bf94d95 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -130,6 +130,12 @@ void Level::save() const return; } + if (m_width > 255 || m_height > 255) { + std::cerr << "Failed to save level!\n" + << "Level save format does not allow widths or heights greater than 255\n"; + return; + } + outputStream.write((char*)&m_width, 1); outputStream.write((char*)&m_height, 1); outputStream.write((char*)m_tiles, m_width * m_height); -- cgit v1.2.3