Skip to content

Commit

Permalink
Merge branch 'main' into olefile-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Nov 11, 2023
2 parents 8a87d37 + 1c2f2c7 commit f783fa8
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ environment:
TEST_OPTIONS:
DEPLOY: YES
matrix:
- PYTHON: C:/Python311
- PYTHON: C:/Python312
ARCHITECTURE: x86
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022
- PYTHON: C:/Python38-x64
Expand Down Expand Up @@ -43,7 +43,7 @@ build_script:

test_script:
- cd c:\pillow
- '%PYTHON%\%EXECUTABLE% -m pip install pytest pytest-cov pytest-timeout'
- '%PYTHON%\%EXECUTABLE% -m pip install pytest pytest-cov pytest-timeout defusedxml numpy olefile pyroma'
- c:\"Program Files (x86)"\"Windows Kits"\10\Debuggers\x86\gflags.exe /p /enable %PYTHON%\%EXECUTABLE%
- '%PYTHON%\%EXECUTABLE% -c "from PIL import Image"'
- '%PYTHON%\%EXECUTABLE% -m pytest -vx --cov PIL --cov Tests --cov-report term --cov-report xml Tests'
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/test-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ jobs:
debian-11-bullseye-amd64,
debian-12-bookworm-x86,
debian-12-bookworm-amd64,
fedora-37-amd64,
fedora-38-amd64,
gentoo,
ubuntu-20.04-focal-amd64,
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ jobs:
- name: Print build system information
run: python3 .github/workflows/system-info.py

- name: python3 -m pip install pytest pytest-cov pytest-timeout defusedxml
run: python3 -m pip install pytest pytest-cov pytest-timeout defusedxml
- name: python3 -m pip install pytest pytest-cov pytest-timeout defusedxml olefile pyroma
run: python3 -m pip install pytest pytest-cov pytest-timeout defusedxml olefile pyroma

- name: Install dependencies
id: install
Expand Down
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
Changelog (Pillow)
==================

10.2.0 (unreleased)
-------------------

- Fixed frombytes() for images with a zero dimension #7493
[radarhere]

10.1.0 (2023-10-15)
-------------------

Expand Down
7 changes: 7 additions & 0 deletions Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,13 @@ def test_zero_tobytes(self, size):
im = Image.new("RGB", size)
assert im.tobytes() == b""

@pytest.mark.parametrize("size", ((1, 0), (0, 1), (0, 0)))
def test_zero_frombytes(self, size):
Image.frombytes("RGB", size, b"")

im = Image.new("RGB", size)
im.frombytes(b"")

def test_has_transparency_data(self):
for mode in ("1", "L", "P", "RGB"):
im = Image.new(mode, (1, 1))
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ def setup(app):
"cwe": ("https://cwe.mitre.org/data/definitions/%s.html", "CWE-%s"),
"issue": (_repo + "issues/%s", "#%s"),
"pr": (_repo + "pull/%s", "#%s"),
"pypi": ("https://pypi.org/project/%s/", "%s"),
}

# sphinxext.opengraph
Expand Down
2 changes: 1 addition & 1 deletion docs/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,6 @@ PIL.OleFileIO
.. versionremoved:: 6.0.0

PIL.OleFileIO was removed as a vendored file in Pillow 4.0.0 (2017-01) in favour of
the upstream olefile Python package, and replaced with an ``ImportError`` in 5.0.0
the upstream :pypi:`olefile` Python package, and replaced with an ``ImportError`` in 5.0.0
(2018-01). The deprecated file has now been removed from Pillow. If needed, install from
PyPI (eg. ``python3 -m pip install olefile``).
4 changes: 4 additions & 0 deletions docs/handbook/image-file-formats.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,8 @@ Pillow reads Kodak FlashPix files. In the current version, only the highest
resolution image is read from the file, and the viewing transform is not taken
into account.

To enable FPX support, you must install :pypi:`olefile`.

.. note::

To enable full FlashPix support, you need to build and install the IJG JPEG
Expand Down Expand Up @@ -1372,6 +1374,8 @@ the first sprite in the file is loaded. You can use :py:meth:`~PIL.Image.Image.s

Note that there may be an embedded gamma of 2.2 in MIC files.

To enable MIC support, you must install :pypi:`olefile`.

MPO
^^^

Expand Down
9 changes: 6 additions & 3 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ Install Pillow with :command:`pip`::
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade Pillow

Optionally, install :pypi:`defusedxml` for Pillow to read XMP data,
and :pypi:`olefile` for Pillow to read FPX and MIC images::

python3 -m pip install --upgrade defusedxml olefile


.. tab:: Linux

Expand Down Expand Up @@ -460,8 +465,6 @@ These platforms are built and tested for every change.
+----------------------------------+----------------------------+---------------------+
| Debian 12 Bookworm | 3.11 | x86, x86-64 |
+----------------------------------+----------------------------+---------------------+
| Fedora 37 | 3.11 | x86-64 |
+----------------------------------+----------------------------+---------------------+
| Fedora 38 | 3.11 | x86-64 |
+----------------------------------+----------------------------+---------------------+
| Gentoo | 3.9 | x86-64 |
Expand All @@ -482,7 +485,7 @@ These platforms are built and tested for every change.
| Windows Server 2022 | 3.8, 3.9, 3.10, 3.11, | x86-64 |
| | 3.12, PyPy3 | |
| +----------------------------+---------------------+
| | 3.11 | x86 |
| | 3.12 | x86 |
| +----------------------------+---------------------+
| | 3.9 (MinGW) | x86-64 |
| +----------------------------+---------------------+
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/ImageFont.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ this class store bitmap fonts, and are used with the

PIL uses its own font file format to store bitmap fonts, limited to 256 characters. You can use
`pilfont.py <https://github.com/python-pillow/pillow-scripts/blob/main/Scripts/pilfont.py>`_
from `pillow-scripts <https://pypi.org/project/pillow-scripts/>`_ to convert BDF and
from :pypi:`pillow-scripts` to convert BDF and
PCF font descriptors (X window font formats) to this format.

Starting with version 1.1.4, PIL can be configured to support TrueType and
Expand Down
4 changes: 2 additions & 2 deletions docs/releasenotes/4.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Pillow 4.0 supports Python 3.6.
OleFileIO.py
============

OleFileIO.py has been removed as a vendored file and is now installed
from the upstream olefile pypi package. All internal dependencies are
``OleFileIO.py`` has been removed as a vendored file and is now installed
from the upstream :pypi:`olefile` PyPI package. All internal dependencies are
redirected to the olefile package. Direct accesses to
``PIL.OlefileIO`` raises a deprecation warning, then patches the
upstream olefile into ``sys.modules`` in its place.
Expand Down
4 changes: 2 additions & 2 deletions docs/releasenotes/5.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Scripts

The scripts formerly installed by Pillow have been split into a
separate package, pillow-scripts, living at
https://github.com/python-pillow/pillow-scripts .
https://github.com/python-pillow/pillow-scripts.


API Changes
Expand All @@ -37,7 +37,7 @@ API Changes
OleFileIO.py
^^^^^^^^^^^^

The olefile module is no longer a required dependency when installing Pillow.
The :pypi:`olefile` module is no longer a required dependency when installing Pillow.
Support for plugins requiring olefile will not be loaded if it is not
installed. This allows library consumers to avoid installing this dependency
if they choose. Some library consumers have little interest in the format
Expand Down
4 changes: 2 additions & 2 deletions docs/releasenotes/6.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Pillow for Python 3.4 is 5.4.1.
Removed deprecated PIL.OleFileIO
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

PIL.OleFileIO was removed as a vendored file and in Pillow 4.0.0 (2017-01) in favour of
the upstream olefile Python package, and replaced with an ``ImportError``. The
``PIL.OleFileIO`` was removed as a vendored file and in Pillow 4.0.0 (2017-01) in favour of
the upstream :pypi:`olefile` Python package, and replaced with an :py:exc:`ImportError`. The
deprecated file has now been removed from Pillow. If needed, install from PyPI (eg.
``python3 -m pip install olefile``).

Expand Down
18 changes: 11 additions & 7 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,9 @@ def frombytes(self, data, decoder_name="raw", *args):
but loads data into this image instead of creating a new image object.
"""

if self.width == 0 or self.height == 0:
return

# may pass tuple instead of argument list
if len(args) == 1 and isinstance(args[0], tuple):
args = args[0]
Expand Down Expand Up @@ -2967,15 +2970,16 @@ def frombytes(mode, size, data, decoder_name="raw", *args):

_check_size(size)

# may pass tuple instead of argument list
if len(args) == 1 and isinstance(args[0], tuple):
args = args[0]
im = new(mode, size)
if im.width != 0 and im.height != 0:
# may pass tuple instead of argument list
if len(args) == 1 and isinstance(args[0], tuple):
args = args[0]

if decoder_name == "raw" and args == ():
args = mode
if decoder_name == "raw" and args == ():
args = mode

im = new(mode, size)
im.frombytes(data, decoder_name, args)
im.frombytes(data, decoder_name, args)
return im


Expand Down

0 comments on commit f783fa8

Please sign in to comment.