Skip to content

Commit 1a51ce7

Browse files
authored
Merge pull request #6699 from hugovk/security-libtiff_buffer
2 parents 2444cdd + 744f455 commit 1a51ce7

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

Tests/test_file_pdf.py

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ def test_save(tmp_path, mode):
4242
helper_save_as_pdf(tmp_path, mode)
4343

4444

45-
@pytest.mark.valgrind_known_error(reason="Temporary skip")
4645
def test_monochrome(tmp_path):
4746
# Arrange
4847
mode = "1"

docs/releasenotes/9.3.0.rst

+6
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ classes: :py:data:`~PIL.ExifTags.Base` and :py:data:`~PIL.ExifTags.GPS`.
4040
Security
4141
========
4242

43+
Initialize libtiff buffer when saving
44+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
45+
46+
When saving a TIFF image to a file object using libtiff, the buffer was not
47+
initialized. This behaviour introduced in Pillow 2.0.0, and has now been fixed.
48+
4349
Decode JPEG compressed BLP1 data in original mode
4450
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4551

src/libImaging/TiffDecode.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -771,11 +771,11 @@ ImagingLibTiffEncodeInit(ImagingCodecState state, char *filename, int fp) {
771771
TRACE(("Opening using fd: %d for writing \n", clientstate->fp));
772772
clientstate->tiff = TIFFFdOpen(fd_to_tiff_fd(clientstate->fp), filename, mode);
773773
} else {
774-
// malloc a buffer to write the tif, we're going to need to realloc or something
774+
// calloc a buffer to write the tif, we're going to need to realloc or something
775775
// if we need bigger.
776776
TRACE(("Opening a buffer for writing \n"));
777-
/* malloc check ok, small constant allocation */
778-
clientstate->data = malloc(bufsize);
777+
/* calloc check ok, small constant allocation */
778+
clientstate->data = calloc(bufsize, 1);
779779
clientstate->size = bufsize;
780780
clientstate->flrealloc = 1;
781781

0 commit comments

Comments
 (0)