From d63684662299279973ac16671dbee80337926bff Mon Sep 17 00:00:00 2001 From: Balint Reczey <balint@balintreczey.hu> Date: Wed, 4 Jan 2017 11:26:05 +0100 Subject: [PATCH 4/8] Return EOF when reading unsigned values hits end of memory backed buffer --- src/actioncompiler/listaction.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/actioncompiler/listaction.c b/src/actioncompiler/listaction.c index 3177956..a24fccf 100644 --- a/src/actioncompiler/listaction.c +++ b/src/actioncompiler/listaction.c @@ -30,6 +30,10 @@ int fileOffset = 0; int readUInt8(Buffer f) { + if (f->buffersize <= fileOffset) + { + return EOF; + } return f->buffer[fileOffset++]; } @@ -45,6 +49,10 @@ int readSInt16(Buffer f) int readUInt16(Buffer f) { + if(f->buffersize <= fileOffset + 1) + { + return EOF; + } return readUInt8(f) + (readUInt8(f)<<8); } @@ -55,6 +63,10 @@ long readSInt32(Buffer f) unsigned long readUInt32(Buffer f) { + if(f->buffersize <= fileOffset + 3) + { + return EOF; + } return (unsigned long)(readUInt8(f) + (readUInt8(f)<<8) + (readUInt8(f)<<16) + (readUInt8(f)<<24)); } -- 2.1.4