mirror of
https://github.com/pret/pokecrystal.git
synced 2026-04-25 15:41:56 -05:00
Fix division by zero risk in make_frames (pokemon_animation.c)
Add validation for width and tilemap_size to prevent division by zero and other invalid calculations from malformed input files.
This commit is contained in:
parent
30bf4af9ad
commit
5c9cccf379
|
|
@ -75,8 +75,17 @@ int bitmask_exists(const struct Bitmask *bitmask, const struct Bitmasks *bitmask
|
|||
}
|
||||
|
||||
void make_frames(const uint8_t *tilemap, long tilemap_size, int width, struct Frames *frames, struct Bitmasks *bitmasks) {
|
||||
if (width <= 0) {
|
||||
error_exit("Error: Invalid width: %d\n", width);
|
||||
}
|
||||
int num_tiles_per_frame = width * width;
|
||||
if (num_tiles_per_frame <= 0 || tilemap_size < num_tiles_per_frame) {
|
||||
error_exit("Error: Invalid tilemap size or width\n");
|
||||
}
|
||||
int num_frames = tilemap_size / num_tiles_per_frame - 1;
|
||||
if (num_frames <= 0) {
|
||||
error_exit("Error: Not enough frames in tilemap\n");
|
||||
}
|
||||
|
||||
frames->frames = xmalloc((sizeof *frames->frames) * num_frames);
|
||||
frames->num_frames = num_frames;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user