HaikuDepot: Fixed reading bigger screenshots
* Increase the RAM limit to 128K per screenshot * Reduce retrieved size to 320 pixel wide * Don't expect to be able to read the stream in one call, read it in 4K chunks. * Print some errors in this code-path to stderr.
This commit is contained in:
@@ -598,7 +598,7 @@ Model::PopulatePackage(const PackageInfoRef& package, uint32 flags)
|
||||
}
|
||||
for (int i = 0; i < screenshotInfos.CountItems(); i++) {
|
||||
const ScreenshotInfo& info = screenshotInfos.ItemAtFast(i);
|
||||
_PopulatePackageScreenshot(package, info, 400, false);
|
||||
_PopulatePackageScreenshot(package, info, 320, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1070,6 +1070,10 @@ Model::_PopulatePackageScreenshot(const PackageInfoRef& package,
|
||||
B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE) == B_OK) {
|
||||
screenshotFile.Write(buffer.Buffer(), buffer.BufferLength());
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "Failed to retrieve screenshot for code '%s' "
|
||||
"at %" B_PRIi32 "x%" B_PRIi32 ".\n", info.Code().String(),
|
||||
scaledWidth, scaledHeight);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -74,16 +74,32 @@ SharedBitmap::SharedBitmap(BPositionIO& data)
|
||||
fMimeType()
|
||||
{
|
||||
status_t status = data.GetSize(&fSize);
|
||||
if (status == B_OK && fSize > 0 && fSize <= 64 * 1024) {
|
||||
const off_t kMaxSize = 128 * 1024;
|
||||
if (status == B_OK && fSize > 0 && fSize <= kMaxSize) {
|
||||
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;
|
||||
if (fBuffer != NULL) {
|
||||
data.Seek(0, SEEK_SET);
|
||||
|
||||
size_t bytesRead = 0;
|
||||
size_t chunkSize = std::min((off_t)4096, fSize);
|
||||
while (bytesRead < fSize) {
|
||||
ssize_t read = data.Read(fBuffer + bytesRead, chunkSize);
|
||||
if (read > 0)
|
||||
bytesRead += read;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (bytesRead != fSize) {
|
||||
delete[] fBuffer;
|
||||
fBuffer = NULL;
|
||||
fSize = 0;
|
||||
}
|
||||
} else
|
||||
fSize = 0;
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "SharedBitmap(): Stream too large: %" B_PRIi64
|
||||
", max: %" B_PRIi64 "\n", fSize, kMaxSize);
|
||||
}
|
||||
|
||||
fBitmap[0] = NULL;
|
||||
|
||||
Reference in New Issue
Block a user