diff --git a/src/client/cl_cin.c b/src/client/cl_cin.c index 44456c67..c135e21a 100644 --- a/src/client/cl_cin.c +++ b/src/client/cl_cin.c @@ -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++; diff --git a/src/client/refresh/files/pcx.c b/src/client/refresh/files/pcx.c index 6ce5cb15..07b91f35 100644 --- a/src/client/refresh/files/pcx.c +++ b/src/client/refresh/files/pcx.c @@ -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) {