Skip to content

Commit

Permalink
Removed realloc
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Dec 28, 2024
1 parent 4e82f2b commit eb49f09
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions src/libImaging/Jpeg2KDecode.c
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ j2k_decode_entry(Imaging im, ImagingCodecState state) {
opj_dparameters_t params;
OPJ_COLOR_SPACE color_space;
j2k_unpacker_t unpack = NULL;
size_t buffer_size = 0, tile_bytes = 0;
size_t tile_bytes = 0;
unsigned n, tile_height, tile_width;
int subsampling;
int total_component_width = 0;
Expand Down Expand Up @@ -870,22 +870,6 @@ j2k_decode_entry(Imaging im, ImagingCodecState state) {
tile_info.data_size = tile_bytes;
}

if (buffer_size < tile_info.data_size) {
/* malloc check ok, overflow and tile size sanity check above */
UINT8 *new = realloc(state->buffer, tile_info.data_size);
if (!new) {
state->errcode = IMAGING_CODEC_MEMORY;
state->state = J2K_STATE_FAILED;
goto quick_exit;
}
/* Undefined behavior, sometimes decode_tile_data doesn't
fill the buffer and we do things with it later, leading
to valgrind errors. */
memset(new, 0, tile_info.data_size);
state->buffer = new;
buffer_size = tile_info.data_size;
}

if (!opj_decode_tile_data(
codec,
tile_info.tile_index,
Expand Down

0 comments on commit eb49f09

Please sign in to comment.