Permalink
Browse files

Changed data handler to not read past the end of the file. Also, chec…

…k the file size when it may read past it.

git-svn-id: https://svn.perian.org/trunk@1428 621663c8-3916-0410-8f58-edc14a8543d5
  • Loading branch information...
gbooker
gbooker committed Apr 16, 2011
1 parent ab3f0a6 commit 595f0d79ed7de69fba17a5c31c52b2cef5e19afa
Showing with 8 additions and 6 deletions.
  1. +8 −6 DataHandlerCallback.cpp
View
@@ -169,6 +169,9 @@ uint32 DataHandlerCallback::read(void *buffer, size_t size)
uint64_t oldPos = mCurrentPosition;
uint8_t *internalBuffer, *myBuffer = (uint8_t *)buffer;
if (mCurrentPosition + size > filesize)
getFileSize();
if (size < 1 || mCurrentPosition > filesize)
return 0;
@@ -186,16 +189,18 @@ uint32 DataHandlerCallback::read(void *buffer, size_t size)
if (size <= 0)
break;
internalBuffer = dataBuffer.GetBuffer(mCurrentPosition, READ_SIZE);
size_t readSize = MIN(READ_SIZE, filesize - mCurrentPosition);
internalBuffer = dataBuffer.GetBuffer(mCurrentPosition, readSize);
if (supportsWideOffsets) {
wide wideOffset = SInt64ToWide(mCurrentPosition);
err = DataHScheduleData64(dataHandler, (Ptr)internalBuffer, &wideOffset,
READ_SIZE, 0, NULL, NULL);
readSize, 0, NULL, NULL);
} else {
err = DataHScheduleData(dataHandler, (Ptr)internalBuffer, mCurrentPosition,
READ_SIZE, 0, NULL, NULL);
readSize, 0, NULL, NULL);
}
if (err) {
@@ -265,9 +270,6 @@ SInt64 DataHandlerCallback::getFileSize()
ComponentResult err = noErr;
wide wideFilesize;
if (filesize > 0)
return filesize;
err = DataHGetFileSize64(dataHandler, &wideFilesize);
if (err == noErr) {
supportsWideOffsets = true;

0 comments on commit 595f0d7

Please sign in to comment.