Skip to content

Commit ee77206

Browse files
Unpack RLE bitmaps before copying in master_load_bitmap_from_res().
This function used the uncompressed size to copy the bitmap bits even when the bitmap was compressed, leading to a buffer overrun. Uncompress if necessary before copying.
1 parent 06d882e commit ee77206

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/GameSrc/citres.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ errtype master_load_bitmap_from_res(grs_bitmap *bmp, Id id_num, int i, LGRect *a
7575
return (ERR_FREAD);
7676
}
7777

78-
const size_t size = f->bm.w * f->bm.h;
7978
if (p == NULL) {
8079
// Caller wants us to allocate a framebuffer.
8180
p = malloc(f->bm.w * f->bm.h);
@@ -91,8 +90,13 @@ errtype master_load_bitmap_from_res(grs_bitmap *bmp, Id id_num, int i, LGRect *a
9190

9291
// Copy the bits.
9392
memcount += f->bm.w * f->bm.h; // FIXME is this needed any more?
94-
memcpy(p, f->bm.bits, f->bm.w * f->bm.h);
95-
93+
if (f->bm.type == BMT_RSD8) {
94+
gr_rsd8_convert(&f->bm, bmp);
95+
// gr_rsd8_convert uses its own buffer, so copy it back.
96+
memcpy(p, bmp->bits, f->bm.w * f->bm.h);
97+
} else {
98+
memcpy(p, f->bm.bits, f->bm.w * f->bm.h);
99+
}
96100
bmp->bits = p;
97101

98102
return (OK);

0 commit comments

Comments
 (0)