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:
Stephan Aßmus
2014-09-13 23:03:58 +02:00
parent ab172803ff
commit e0881f2139
2 changed files with 29 additions and 9 deletions
+5 -1
View File
@@ -598,7 +598,7 @@ Model::PopulatePackage(const PackageInfoRef& package, uint32 flags)
} }
for (int i = 0; i < screenshotInfos.CountItems(); i++) { for (int i = 0; i < screenshotInfos.CountItems(); i++) {
const ScreenshotInfo& info = screenshotInfos.ItemAtFast(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) { B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE) == B_OK) {
screenshotFile.Write(buffer.Buffer(), buffer.BufferLength()); 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);
} }
} }
+24 -8
View File
@@ -74,16 +74,32 @@ SharedBitmap::SharedBitmap(BPositionIO& data)
fMimeType() fMimeType()
{ {
status_t status = data.GetSize(&fSize); 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]; fBuffer = new(std::nothrow) uint8[fSize];
if (fBuffer != NULL) {
data.Seek(0, SEEK_SET); data.Seek(0, SEEK_SET);
ssize_t read = data.Read(fBuffer, fSize);
if (read != fSize) { size_t bytesRead = 0;
delete[] fBuffer; size_t chunkSize = std::min((off_t)4096, fSize);
fBuffer = NULL; 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; fSize = 0;
} } else {
fprintf(stderr, "SharedBitmap(): Stream too large: %" B_PRIi64
", max: %" B_PRIi64 "\n", fSize, kMaxSize);
} }
fBitmap[0] = NULL; fBitmap[0] = NULL;