Skip to content

Commit 6758800

Browse files
src/__init__.py tests/: fix Pixmap.is_unicolor segv if pixmap is empty.
This partially addresses #4466.
1 parent 9335413 commit 6758800

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10258,11 +10258,13 @@ def _pixmap_read_samples(pm, offset, n):
1025810258
for i in range(n):
1025910259
ret.append(mupdf.fz_samples_get(pm, offset+i))
1026010260
return ret
10261-
sample0 = _pixmap_read_samples( pm, 0, n)
10262-
for offset in range( n, count, n):
10263-
sample = _pixmap_read_samples( pm, offset, n)
10264-
if sample != sample0:
10265-
return False
10261+
for offset in range( 0, count, n):
10262+
if offset == 0:
10263+
sample0 = _pixmap_read_samples( pm, 0, n)
10264+
else:
10265+
sample = _pixmap_read_samples( pm, offset, n)
10266+
if sample != sample0:
10267+
return False
1026610268
return True
1026710269

1026810270
@property

tests/test_4466.pdf

1020 KB
Binary file not shown.

tests/test_general.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,3 +1685,12 @@ def test_4415():
16851685
pixmap.save(path_out)
16861686
rms = gentle_compare.pixmaps_rms(path_out_expected, path_out)
16871687
assert rms == 0, f'{rms=}'
1688+
1689+
def test_4466():
1690+
path = os.path.normpath(f'{__file__}/../../tests/test_4466.pdf')
1691+
with pymupdf.Document(path) as document:
1692+
for page in document:
1693+
print(f'{page=}', flush=1)
1694+
pixmap = page.get_pixmap(clip=(0, 0, 10, 10))
1695+
print(f'{pixmap.n=} {pixmap.size=} {pixmap.stride=} {pixmap.width=} {pixmap.height=} {pixmap.x=} {pixmap.y=}', flush=1)
1696+
pixmap.is_unicolor # Used to crash.

0 commit comments

Comments
 (0)