@@ -46,10 +46,11 @@ #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFOutOfRangeException.h" #import "OFSetOptionFailedException.h" +#import "OFTruncatedDataException.h" #import "of_asprintf.h" #define MIN_READ_SIZE 512 @@ -174,13 +175,17 @@ - (void)readIntoBuffer: (void *)buffer exactLength: (size_t)length { size_t readLength = 0; - while (readLength < length) + while (readLength < length) { + if ([self isAtEndOfStream]) + @throw [OFTruncatedDataException exception]; + readLength += [self readIntoBuffer: (char *)buffer + readLength length: length - readLength]; + } } #ifdef OF_HAVE_SOCKETS - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length