diff --git a/src/apps/haikudepot/PackageInfo.cpp b/src/apps/haikudepot/PackageInfo.cpp index 71457dc82b..37176d8406 100644 --- a/src/apps/haikudepot/PackageInfo.cpp +++ b/src/apps/haikudepot/PackageInfo.cpp @@ -64,16 +64,26 @@ SharedBitmap::SharedBitmap(const char* mimeType) } -SharedBitmap::SharedBitmap(const BMallocIO& data) +SharedBitmap::SharedBitmap(BPositionIO& data) : BReferenceable(), fResourceID(-1), - fBuffer(new(std::nothrow) uint8[data.BufferLength()]), - fSize(data.BufferLength()), + fBuffer(NULL), + fSize(0), fMimeType() { - if (fBuffer != NULL) - memcpy(fBuffer, data.Buffer(), fSize); + status_t status = data.GetSize(&fSize); + if (status == B_OK && fSize > 0 && fSize <= 64 * 1024) { + fBuffer = new(std::nothrow) uint8[fSize]; + + data.Seek(0, SEEK_SET); + ssize_t read = data.Read(fBuffer, fSize); + if (read != fSize) { + delete[] fBuffer; + fBuffer = NULL; + fSize = 0; + } + } fBitmap[0] = NULL; fBitmap[1] = NULL; diff --git a/src/apps/haikudepot/PackageInfo.h b/src/apps/haikudepot/PackageInfo.h index 23a61ec756..30d42182c8 100644 --- a/src/apps/haikudepot/PackageInfo.h +++ b/src/apps/haikudepot/PackageInfo.h @@ -16,7 +16,7 @@ class BBitmap; -class BMallocIO; +class BPositionIO; class SharedBitmap : public BReferenceable { @@ -31,7 +31,7 @@ public: SharedBitmap(BBitmap* bitmap); SharedBitmap(int32 resourceID); SharedBitmap(const char* mimeType); - SharedBitmap(const BMallocIO& data); + SharedBitmap(BPositionIO& data); ~SharedBitmap(); const BBitmap* Bitmap(Size which); @@ -49,7 +49,7 @@ private: private: int32 fResourceID; uint8* fBuffer; - size_t fSize; + off_t fSize; BString fMimeType; BBitmap* fBitmap[3]; };