SAGA2: Added safeguards to sprite unpacking

This commit is contained in:
Eugene Sandulenko 2021-06-18 23:27:30 +02:00
parent 36e9a264c8
commit 9565ea67a3
No known key found for this signature in database
GPG Key ID: 014D387312D34F08
2 changed files with 18 additions and 5 deletions

View File

@ -110,6 +110,11 @@ void unpackSprite(gPixelMap *map, uint8 *sprData) {
while (true) {
byte trans = *sprData++;
if (bytes < trans) {
warning("unpackSprite: too many trans %d < %d", bytes, trans);
trans = bytes;
break;
}
memset(dst, 0, trans);
dst += trans;
bytes -= trans;
@ -118,6 +123,10 @@ void unpackSprite(gPixelMap *map, uint8 *sprData) {
break;
byte fill = *sprData++;
if (bytes < fill) {
warning("unpackSprite: too many bytes %d < %d", bytes, fill);
fill = bytes;
}
memcpy(dst, sprData, fill);
dst += fill;
bytes -= fill;

View File

@ -530,11 +530,11 @@ void *LoadResource(hResContext *con, uint32 id, const char desc[]) {
idString[0] = id;
idString[1] = 0;
debugC(3, kDebugResources, "Loading resource %d (%s, %s)", id, tag2str(id), desc);
debugC(3, kDebugResources, "LoadResource(): Loading resource %d (%s, %s)", id, tag2str(id), desc);
size = con->size(id);
if (size <= 0 || !con->seek(id)) {
error("Error reading resource ID '%s'.", &idString);
error("LoadResource(): Error reading resource ID '%s'.", &idString);
}
// Allocate the buffer
@ -552,11 +552,11 @@ Common::SeekableReadStream *loadResourceToStream(hResContext *con, uint32 id, co
idString[0] = id;
idString[1] = 0;
debugC(3, kDebugResources, "Loading resource %d (%s, %s)", id, tag2str(id), desc);
debugC(3, kDebugResources, "loadResourceToStream(): Loading resource %d (%s, %s)", id, tag2str(id), desc);
size = con->size(id);
if (size <= 0 || !con->seek(id)) {
error("Error reading resource ID '%s'.", &idString);
error("loadResourceToStream(): Error reading resource ID '%s'.", &idString);
}
// Allocate the buffer
@ -577,10 +577,11 @@ RHANDLE LoadResourceToHandle(hResContext *con, uint32 id, const char desc[]) {
idString[0] = id;
idString[1] = 0;
debugC(3, kDebugResources, "LoadResourceToHandle(): Loading resource %d (%s, %s)", id, tag2str(id), desc);
size = con->size(id);
if (size <= 0 || !con->seek(id)) {
error("Error reading resource ID '%s'.", &idString);
error("LoadResourceToHandle(): Error reading resource ID '%s'.", &idString);
}
// Allocate the buffer
@ -978,6 +979,9 @@ APPFUNC(cmdWindowFunc) {
GameMode::modeStackPtr[GameMode::modeStackCtr - 1]->handleKey(key, qual);
break;
default:
break;
}
}