[Scummvm-cvs-logs] SF.net SVN: scummvm: [28536] scummvm/trunk/engines/gob/dataio.cpp
drmccoy at users.sourceforge.net
drmccoy at users.sourceforge.net
Sat Aug 11 22:59:08 CEST 2007
Revision: 28536
http://scummvm.svn.sourceforge.net/scummvm/?rev=28536&view=rev
Author: drmccoy
Date: 2007-08-11 13:59:08 -0700 (Sat, 11 Aug 2007)
Log Message:
-----------
Added a small safety check to avoid accidently overflowing buffers when reading from files in STKs
Modified Paths:
--------------
scummvm/trunk/engines/gob/dataio.cpp
Modified: scummvm/trunk/engines/gob/dataio.cpp
===================================================================
--- scummvm/trunk/engines/gob/dataio.cpp 2007-08-11 20:55:43 UTC (rev 28535)
+++ scummvm/trunk/engines/gob/dataio.cpp 2007-08-11 20:59:08 UTC (rev 28536)
@@ -273,28 +273,27 @@
file = (handle - 50) / 10;
slot = (handle - 50) % 10;
- if (!_isCurrentSlot[file * MAX_SLOT_COUNT + slot]) {
+ int index = file * MAX_SLOT_COUNT + slot;
+
+ _chunkPos[index] = CLIP<int32>(_chunkPos[index], 0, _chunkSize[index]);
+
+ if (!_isCurrentSlot[index]) {
for (i = 0; i < MAX_SLOT_COUNT; i++)
_isCurrentSlot[file * MAX_SLOT_COUNT + i] = false;
- offset = _chunkOffset[file * MAX_SLOT_COUNT + slot] +
- _chunkPos[file * MAX_SLOT_COUNT + slot];
+ offset = _chunkOffset[index] + _chunkPos[index];
- debugC(7, kDebugFileIO, "seek: %d, %d",
- _chunkOffset[file * MAX_SLOT_COUNT + slot],
- _chunkPos[file * MAX_SLOT_COUNT + slot]);
+ debugC(7, kDebugFileIO, "seek: %d, %d", _chunkOffset[index], _chunkPos[index]);
file_getHandle(_dataFileHandles[file])->seek(offset, SEEK_SET);
}
- _isCurrentSlot[file * MAX_SLOT_COUNT + slot] = true;
- if ((_chunkPos[file * MAX_SLOT_COUNT + slot] + size) >
- (_chunkSize[file * MAX_SLOT_COUNT + slot]))
- size = _chunkSize[file * MAX_SLOT_COUNT + slot] -
- _chunkPos[file * MAX_SLOT_COUNT + slot];
+ _isCurrentSlot[index] = true;
+ if ((_chunkPos[index] + size) > (_chunkSize[index]))
+ size = _chunkSize[index] - _chunkPos[index];
file_getHandle(_dataFileHandles[file])->read(buf, size);
- _chunkPos[file * MAX_SLOT_COUNT + slot] += size;
+ _chunkPos[index] += size;
return size;
}
@@ -307,13 +306,15 @@
file = (handle - 50) / 10;
slot = (handle - 50) % 10;
- _isCurrentSlot[file * MAX_SLOT_COUNT + slot] = false;
+ int index = file * MAX_SLOT_COUNT + slot;
+
+ _isCurrentSlot[index] = false;
if (from == SEEK_SET)
- _chunkPos[file * MAX_SLOT_COUNT + slot] = pos;
+ _chunkPos[index] = pos;
else
- _chunkPos[file * MAX_SLOT_COUNT + slot] += pos;
+ _chunkPos[index] += pos;
- return _chunkPos[file * MAX_SLOT_COUNT + slot];
+ return _chunkPos[index];
}
uint32 DataIO::getChunkPos(int16 handle) const {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list