Initialize buffer with 0, fixes valgrind undefined behavior issues

This commit is contained in:
Eric Soroos 2021-04-09 13:41:07 +02:00
parent 43aa6ade6f
commit 441e6426ae
3 changed files with 6 additions and 2 deletions

View File

@ -199,7 +199,7 @@ _setimage(ImagingDecoderObject *decoder, PyObject *args) {
state->bytes = (state->bits * state->xsize + 7) / 8;
}
/* malloc check ok, overflow checked above */
state->buffer = (UINT8 *)malloc(state->bytes);
state->buffer = (UINT8 *)calloc(1, state->bytes);
if (!state->buffer) {
return ImagingError_MemoryError();
}

View File

@ -264,7 +264,7 @@ _setimage(ImagingEncoderObject *encoder, PyObject *args) {
}
state->bytes = (state->bits * state->xsize + 7) / 8;
/* malloc check ok, overflow checked above */
state->buffer = (UINT8 *)malloc(state->bytes);
state->buffer = (UINT8 *)calloc(1, state->bytes);
if (!state->buffer) {
return ImagingError_MemoryError();
}

View File

@ -861,6 +861,10 @@ j2k_decode_entry(Imaging im, ImagingCodecState state) {
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;
}