From 036297b605dbaf4894a3ea2c560d99a53e84c092 Mon Sep 17 00:00:00 2001 From: Vladimir Serbinenko Date: Sun, 7 May 2023 03:23:07 +0200 Subject: [PATCH] DIRECTOR: Fix use-after-free --- engines/director/archive.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/engines/director/archive.cpp b/engines/director/archive.cpp index 8b14fe2ddbf..885d68157c1 100644 --- a/engines/director/archive.cpp +++ b/engines/director/archive.cpp @@ -570,6 +570,7 @@ bool RIFXArchive::openStream(Common::SeekableReadStream *stream, uint32 startOff _isBigEndian = false; } else { warning("RIFXArchive::openStream(): RIFX or XFIR expected but %s found", tag2str(headerTag)); + _stream = nullptr; return false; } @@ -641,8 +642,10 @@ bool RIFXArchive::openStream(Common::SeekableReadStream *stream, uint32 startOff delete dumpStream; // If we couldn't read the map, we can't do anything past this point. - if (!readMapSuccess) + if (!readMapSuccess) { + _stream = nullptr; return false; + } if (_rifxType == MKTAG('A', 'P', 'P', 'L')) { if (hasResource(MKTAG('F', 'i', 'l', 'e'), -1)) { @@ -654,6 +657,7 @@ bool RIFXArchive::openStream(Common::SeekableReadStream *stream, uint32 startOff return openStream(_stream, fileOffset); } else { warning("No 'File' resource present in APPL archive"); + _stream = nullptr; return false; } }