mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 09:26:16 +03:00
Initialize buffer with 0, fixes valgrind undefined behavior issues
This commit is contained in:
parent
43aa6ade6f
commit
441e6426ae
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user