aboutsummaryrefslogtreecommitdiff
path: root/src/sparse/sparse.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/sparse/sparse.cpp')
-rw-r--r--src/sparse/sparse.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/sparse/sparse.cpp b/src/sparse/sparse.cpp
index 6d1b621..6cf2df2 100644
--- a/src/sparse/sparse.cpp
+++ b/src/sparse/sparse.cpp
@@ -261,7 +261,12 @@ int DecompressSparse(void * pvOutBuffer, int * pcbOutBuffer, void * pvInBuffer,
// If highest bit, it means that that normal data follow
if(OneByte & 0x80)
{
+ // Check the length of one chunk. Check for overflows
cbChunkSize = (OneByte & 0x7F) + 1;
+ if((pbInBuffer + cbChunkSize) > pbInBufferEnd)
+ return 0;
+
+ // Copy the chunk. Make sure that the buffer won't overflow
cbChunkSize = (cbChunkSize < cbOutBuffer) ? cbChunkSize : cbOutBuffer;
memcpy(pbOutBuffer, pbInBuffer, cbChunkSize);
pbInBuffer += cbChunkSize;