Skip to content

Commit ca4c8a7

Browse files
committed
FLI: Check image dimensions
1 parent f1099b4 commit ca4c8a7

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/sail-codecs/fli/fli.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,21 @@ SAIL_EXPORT sail_status_t sail_codec_save_seek_next_frame_v8_fli(void* state, co
397397
/* Determine if we're writing FLI or FLC. */
398398
fli_state->is_fli = (image->width == 320 && image->height == 200);
399399

400+
/* Validate dimensions fit in uint16_t. */
401+
if (image->width > UINT16_MAX || image->height > UINT16_MAX)
402+
{
403+
SAIL_LOG_ERROR("FLI: Image dimensions %ux%u exceed maximum allowed (%ux%u)",
404+
image->width, image->height, UINT16_MAX, UINT16_MAX);
405+
SAIL_LOG_AND_RETURN(SAIL_ERROR_INVALID_IMAGE);
406+
}
407+
400408
/* Fill FLI header. */
401409
memset(&fli_state->fli_header, 0, sizeof(fli_state->fli_header));
402410
fli_state->fli_header.size = 0;
403411
fli_state->fli_header.magic = fli_state->is_fli ? SAIL_FLI_MAGIC : SAIL_FLC_MAGIC;
404412
fli_state->fli_header.frames = 0;
405-
fli_state->fli_header.width = image->width;
406-
fli_state->fli_header.height = image->height;
413+
fli_state->fli_header.width = (uint16_t)image->width;
414+
fli_state->fli_header.height = (uint16_t)image->height;
407415
fli_state->fli_header.depth = 8;
408416
fli_state->fli_header.flags = 0;
409417

0 commit comments

Comments
 (0)