From ac9830614d07d80f0c02d9d7c75d709f9d534466 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 8 Dec 2018 17:28:57 -0800 Subject: GLK: GLULXE: Validate game file version --- engines/glk/glulxe/glulxe.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'engines/glk/glulxe/glulxe.cpp') diff --git a/engines/glk/glulxe/glulxe.cpp b/engines/glk/glulxe/glulxe.cpp index 25af4c2f4d..e2e1a477e5 100644 --- a/engines/glk/glulxe/glulxe.cpp +++ b/engines/glk/glulxe/glulxe.cpp @@ -27,10 +27,16 @@ namespace Glk { namespace Glulxe { -Glulxe::Glulxe(OSystem *syst, const GlkGameDescription &gameDesc) : GlkAPI(syst, gameDesc) { +Glulxe::Glulxe(OSystem *syst, const GlkGameDescription &gameDesc) : GlkAPI(syst, gameDesc), + vm_exited_cleanly(false) { } void Glulxe::runGame(Common::SeekableReadStream *gameFile) { + _gameFile = gameFile; + + if (!is_gamefile_valid()) + return; + // TODO } @@ -44,5 +50,30 @@ Common::Error Glulxe::saveGameData(strid_t file, const Common::String &desc) { return Common::kNoError; } +bool Glulxe::is_gamefile_valid() { + if (_gameFile->size() < 8) { + GUIError(_("This is too short to be a valid Glulx file.")); + return false; + } + + if (_gameFile->readUint32BE() != MKTAG('G', 'l', 'u', 'l')) { + GUIError(_("This is not a valid Glulx file.")); + return false; + } + + // We support version 2.0 through 3.1.* + uint version = _gameFile->readUint32BE(); + if (version < 0x20000) { + GUIError(_("This Glulx file is too old a version to execute.")); + return false; + } + if (version >= 0x30200) { + GUIError(_("This Glulx file is too new a version to execute.")); + return false; + } + + return true; +} + } // End of namespace Glulxe } // End of namespace Glk -- cgit v1.2.3