Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/JPEGView/ImageLoadThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1057,20 +1057,24 @@ void CImageLoadThread::ProcessReadGDIPlusRequest(CRequest * request) {
bool isOutOfMemory, isAnimatedGIF;
request->Image = ConvertGDIPlusBitmapToJPEGImage(pBitmap, request->FrameIndex, NULL, 0, isOutOfMemory, isAnimatedGIF);
request->OutOfMemory = request->Image == NULL && isOutOfMemory;
if (request->OutOfMemory && GetBitmapFormat(pBitmap) == IF_TIFF) {
DeleteCachedGDIBitmap();
return ProcessReadWICRequest(request);
}
if (!isAnimatedGIF) {
DeleteCachedGDIBitmap();
}
}

static unsigned char* alloc(int sizeInBytes) {
static unsigned char* alloc(size_t sizeInBytes) {
return new(std::nothrow) unsigned char[sizeInBytes];
}

static void dealloc(unsigned char* buffer) {
delete[] buffer;
}

typedef unsigned char* Allocator(int sizeInBytes);
typedef unsigned char* Allocator(size_t sizeInBytes);
typedef void Deallocator(unsigned char* buffer);

__declspec(dllimport) unsigned char* __stdcall LoadImageWithWIC(LPCWSTR fileName, Allocator* allocator, Deallocator* deallocator,
Expand Down
4 changes: 2 additions & 2 deletions src/WICLoader/MaxImageDef.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#pragma once

#ifdef _WIN64
const unsigned int MAX_IMAGE_PIXELS = 1024 * 1024 * 300;
const unsigned int MAX_IMAGE_PIXELS = 65535 * 65535;
#else
const unsigned int MAX_IMAGE_PIXELS = 1024 * 1024 * 100;
#endif

// That must not be bigger than 65535 due to internal limitations
const unsigned int MAX_IMAGE_DIMENSION = 65535;
const unsigned int MAX_IMAGE_DIMENSION = 65535;
4 changes: 2 additions & 2 deletions src/WICLoader/WICLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// forward declaration
static HRESULT CopyWICBitmapToBuffer(IWICBitmapSource *piBitmapSource, byte* pBuffer);

typedef byte* Allocator(int sizeInBytes);
typedef byte* Allocator(size_t sizeInBytes);
typedef void Deallocator(byte* buffer);

// Checks if WIC is installed by asking for the WIC imaging factory.
Expand Down Expand Up @@ -65,7 +65,7 @@ __declspec(dllexport) byte* __stdcall LoadImageWithWIC(LPCWSTR fileName, Allocat
piBitmapFrame->GetSize(width, height);
if (*width <= MAX_IMAGE_DIMENSION && *height <= MAX_IMAGE_DIMENSION) {
if ((double)*width * *height <= MAX_IMAGE_PIXELS) {
bitmapBuffer = allocator(*width * *height * 4);
bitmapBuffer = allocator((size_t)*width * *height * 4);
if (bitmapBuffer != NULL) {
hr = CopyWICBitmapToBuffer(piBitmapFrame, bitmapBuffer);
if (!SUCCEEDED(hr)) {
Expand Down