STARTREK: Ensure that we're not reading past the end of RDF files

This commit is contained in:
Filippos Karapetis 2020-12-29 04:33:42 +02:00
parent 2761107ae3
commit c6d3f1df65

View File

@ -122,25 +122,32 @@ Room::~Room() {
void Room::loadRoomMessages() {
// TODO: There are some more messages which are not stored in that offset
uint16 messagesOffset = readRdfWord(32);
uint16 offset = messagesOffset;
const char *text = (const char *)_rdfData + messagesOffset;
const char roomIndexChar = '0' + _vm->_roomIndex;
do {
while (text[0] != '#' || (text[1] != _vm->_missionName[0] && text[4] != roomIndexChar))
while ((text[0] != '#' || (text[1] != _vm->_missionName[0] && text[4] != roomIndexChar)) && offset < _rdfSize) {
text++;
offset++;
}
if (text[5] == '\\')
loadRoomMessage(text);
while (*text != '\0')
while (*text != '\0' && offset < _rdfSize) {
text++;
offset++;
}
// Peek the next byte, in case there's a filler text
if (Common::isAlpha(*(text + 1))) {
while (*text != '\0')
while (*text != '\0' && offset < _rdfSize) {
text++;
offset++;
}
}
} while (*(text + 1) == '#');
} while (*(text + 1) == '#' && offset < _rdfSize);
}
void Room::loadRoomMessage(const char *text) {