Skip to content

Commit

Permalink
do not accept int in PIL._binary.i8
Browse files Browse the repository at this point in the history
  • Loading branch information
nulano committed Dec 31, 2023
1 parent 6a33d6d commit 3396ce1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 9 additions & 6 deletions src/PIL/IptcImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,29 @@
import tempfile

from . import Image, ImageFile
from ._binary import i8, o8
from ._binary import i16be as i16
from ._binary import i32be as i32

COMPRESSION = {1: "raw", 5: "jpeg"}

PAD = o8(0) * 4
PAD = b"\0\0\0\0"


#
# Helpers


def _i8(c: int | bytes) -> int:
return c if isinstance(c, int) else c[0]


def i(c):
return i32((PAD + c)[-4:])


def dump(c):
for i in c:
print("%02x" % i8(i), end=" ")
print("%02x" % _i8(i), end=" ")
print()


Expand Down Expand Up @@ -103,10 +106,10 @@ def _open(self):
self.info[tag] = tagdata

# mode
layers = i8(self.info[(3, 60)][0])
component = i8(self.info[(3, 60)][1])
layers = self.info[(3, 60)][0]
component = self.info[(3, 60)][1]

Check warning on line 110 in src/PIL/IptcImagePlugin.py

View check run for this annotation

Codecov / codecov/patch

src/PIL/IptcImagePlugin.py#L110

Added line #L110 was not covered by tests
if (3, 65) in self.info:
id = i8(self.info[(3, 65)][0]) - 1
id = self.info[(3, 65)][0] - 1

Check warning on line 112 in src/PIL/IptcImagePlugin.py

View check run for this annotation

Codecov / codecov/patch

src/PIL/IptcImagePlugin.py#L112

Added line #L112 was not covered by tests
else:
id = 0
if layers == 1 and not component:
Expand Down
4 changes: 2 additions & 2 deletions src/PIL/_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
from struct import pack, unpack_from


def i8(c: int | bytes) -> int:
return c if c.__class__ is int else c[0] # type: ignore[index, return-value]
def i8(c: bytes) -> int:
return c[0]


def o8(i: int) -> bytes:
Expand Down

0 comments on commit 3396ce1

Please sign in to comment.