Skip to content

Commit

Permalink
Fixed crash in RLE colorkey blitting
Browse files Browse the repository at this point in the history
Fixes Maelstrom running over sdl2-compat with SDL3
  • Loading branch information
slouken committed Oct 9, 2024
1 parent f946f87 commit 9023a19
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/video/SDL_RLEaccel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ static bool RLEAlphaSurface(SDL_Surface *surface)
return false;
}
// save the destination format so we can undo the encoding later
*(SDL_PixelFormat *)rlebuf = df->format;
*(SDL_PixelFormat *)rlebuf = dest->format;
dst = rlebuf + sizeof(SDL_PixelFormat);

// Do the actual encoding
Expand Down Expand Up @@ -1232,6 +1232,7 @@ static const getpix_func getpixes[4] = {

static bool RLEColorkeySurface(SDL_Surface *surface)
{
SDL_Surface *dest;
Uint8 *rlebuf, *dst;
int maxn;
int y;
Expand All @@ -1242,6 +1243,11 @@ static bool RLEColorkeySurface(SDL_Surface *surface)
Uint32 ckey, rgbmask;
int w, h;

dest = surface->map.info.dst_surface;
if (!dest) {
return false;
}

// calculate the worst case size for the compressed surface
switch (bpp) {
case 1:
Expand All @@ -1263,15 +1269,18 @@ static bool RLEColorkeySurface(SDL_Surface *surface)
return false;
}

maxsize += sizeof(SDL_PixelFormat);
rlebuf = (Uint8 *)SDL_malloc(maxsize);
if (!rlebuf) {
return false;
}
// save the destination format so we can undo the encoding later
*(SDL_PixelFormat *)rlebuf = dest->format;

// Set up the conversion
srcbuf = (Uint8 *)surface->pixels;
maxn = bpp == 4 ? 65535 : 255;
dst = rlebuf;
dst = rlebuf + sizeof(SDL_PixelFormat);
rgbmask = ~surface->fmt->Amask;
ckey = surface->map.info.colorkey & rgbmask;
lastline = dst;
Expand Down

0 comments on commit 9023a19

Please sign in to comment.