pcx: fix support of bytes_per_line

https://github.com/yquake2/yquake2/issues/1119
This commit is contained in:
Denis Pauk 2024-07-06 16:32:01 +03:00
parent 3f6a0a3689
commit bfeb842bd3
2 changed files with 15 additions and 3 deletions

View File

@ -85,7 +85,7 @@ SCR_LoadPCX(char *filename, byte **pic, byte **palette, int *width, int *height)
{
byte *raw;
pcx_t *pcx;
int x, y;
int x, y, bpl;
int len, full_size;
int dataByte, runLength;
byte *out, *pix;
@ -115,6 +115,12 @@ SCR_LoadPCX(char *filename, byte **pic, byte **palette, int *width, int *height)
return;
}
bpl = LittleShort(pcx->bytes_per_line);
if (bpl <= pcx->xmax)
{
bpl = pcx->xmax + 1;
}
full_size = (pcx->ymax + 1) * (pcx->xmax + 1);
out = Z_Malloc(full_size);
@ -140,7 +146,7 @@ SCR_LoadPCX(char *filename, byte **pic, byte **palette, int *width, int *height)
for (y = 0; y <= pcx->ymax; y++, pix += pcx->xmax + 1)
{
for (x = 0; x <= pcx->xmax; )
for (x = 0; x < bpl; )
{
dataByte = *raw++;

View File

@ -173,6 +173,12 @@ LoadPCX(const char *origname, byte **pic, byte **palette, int *width, int *heigh
return;
}
if (pcx->bytes_per_line <= pcx_width)
{
pcx->bytes_per_line = pcx_width + 1;
image_issues = true;
}
full_size = (pcx_height + 1) * (pcx_width + 1);
out = malloc(full_size);
if (!out)
@ -218,7 +224,7 @@ LoadPCX(const char *origname, byte **pic, byte **palette, int *width, int *heigh
for (y = 0; y <= pcx_height; y++, pix += pcx_width + 1)
{
for (x = 0; x <= pcx_width; )
for (x = 0; x < pcx->bytes_per_line; )
{
if (raw - (byte *)pcx > len)
{