[go: up one dir, main page]

Page MenuHomePhabricator

FancyCaptcha isn't compatible with pillow 10.x
Closed, ResolvedPublicBUG REPORT

Description

install (current) Pillow

pip install pillow (comment: Pillow 10.x was installed)

python3 captcha.py --font=/usr/share/fonts/truetype/freefont/FreeSansBold.ttf --wordlist=/usr/share/dict/words --key=wikiFOO --output=../../resources/assets/captcha --count=100
Generating 100 CAPTCHA images separated in 100 image(s) per chunk run by 1 threads...
multiprocessing.pool.RemoteTraceback:
"""
Traceback (most recent call last):
  File "/usr/lib/python3.10/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "/usr/lib/python3.10/multiprocessing/pool.py", line 48, in mapstar
    return list(map(*args))
  File "/var/www/vhosts/compusofia.com/httpdocs/w/extensions/ConfirmEdit/captcha.py", line 218, in run_in_thread
    gen_captcha(word, font, fontsize, os.path.join(output, filename))
  File "/var/www/vhosts/compusofia.com/httpdocs/w/extensions/ConfirmEdit/captcha.py", line 84, in gen_captcha
    dim = font.getsize(text)
AttributeError: 'FreeTypeFont' object has no attribute 'getsize'
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/var/www/vhosts/compusofia.com/httpdocs/w/extensions/ConfirmEdit/captcha.py", line 301, in <module>
    p.map(run_in_thread, data)
  File "/usr/lib/python3.10/multiprocessing/pool.py", line 367, in map
    return self._map_async(func, iterable, mapstar, chunksize).get()
  File "/usr/lib/python3.10/multiprocessing/pool.py", line 774, in get
    raise self._value
AttributeError: 'FreeTypeFont' object has no attribute 'getsize'

outcome: no captchas created

install Pillow 9.5.0

pip uninstall Pillow
pip install Pillow==9.5.0

python3 captcha.py --font=/usr/share/fonts/truetype/freefont/FreeSansBold.ttf --wordlist=/usr/share/dict/words --key=wikiFOO --output=../../resources/assets/captcha --count=100
Generating 100 CAPTCHA images separated in 100 image(s) per chunk run by 1 threads...
/var/www/vhosts/compusofia.com/httpdocs/w/extensions/ConfirmEdit/captcha.py:84:** DeprecationWarning: getsize is deprecated and will be removed in Pillow 10** (2023-07-01). Use getbbox or getlength instead.
  dim = font.getsize(text)

outcome: captchas successfully created

Software version
Mediawiki 1.4.1 - ConfirmEdit from .gz file

Other information
Ubuntu 22.04.3 LTS, python3.10, Pillow 10.x.x, Pillow 9.5.0

Event Timeline

Pppery renamed this task from xtension:ConfirmEdit/FancyCaptcha: creating captcha files is either not working or throws error to FancyCaptcha: creating captcha files is either not working or throws error.Dec 29 2023, 6:35 PM
Reedy renamed this task from FancyCaptcha: creating captcha files is either not working or throws error to FancyCaptcha isn't compatible with pillow 10.x.Jan 2 2024, 2:35 AM

Change 986864 had a related patch set uploaded (by Reedy; author: Reedy):

[mediawiki/extensions/ConfirmEdit@master] captcha(-old).py: Support Pillow 10

https://gerrit.wikimedia.org/r/986864

Change 986864 merged by jenkins-bot:

[mediawiki/extensions/ConfirmEdit@master] captcha(-old).py: Support Pillow 10

https://gerrit.wikimedia.org/r/986864

Change 987986 had a related patch set uploaded (by Reedy; author: Reedy):

[mediawiki/extensions/ConfirmEdit@REL1_41] captcha(-old).py: Support Pillow 10

https://gerrit.wikimedia.org/r/987986

Change 987987 had a related patch set uploaded (by Reedy; author: Reedy):

[mediawiki/extensions/ConfirmEdit@REL1_40] captcha(-old).py: Support Pillow 10

https://gerrit.wikimedia.org/r/987987

Change 987988 had a related patch set uploaded (by Reedy; author: Reedy):

[mediawiki/extensions/ConfirmEdit@REL1_39] captcha(-old).py: Support Pillow 10

https://gerrit.wikimedia.org/r/987988

Reedy claimed this task.

Change 987986 merged by jenkins-bot:

[mediawiki/extensions/ConfirmEdit@REL1_41] captcha(-old).py: Support Pillow 10

https://gerrit.wikimedia.org/r/987986

Change 987988 merged by jenkins-bot:

[mediawiki/extensions/ConfirmEdit@REL1_39] captcha(-old).py: Support Pillow 10

https://gerrit.wikimedia.org/r/987988

Change 987987 merged by jenkins-bot:

[mediawiki/extensions/ConfirmEdit@REL1_40] captcha(-old).py: Support Pillow 10

https://gerrit.wikimedia.org/r/987987

Change 993220 had a related patch set uploaded (by Reedy; author: Reedy):

[mediawiki/extensions/ConfirmEdit@master] captca.py: Fix PIL 10 support again

https://gerrit.wikimedia.org/r/993220

Change 993220 merged by jenkins-bot:

[mediawiki/extensions/ConfirmEdit@master] captca.py: Fix PIL 10 support again

https://gerrit.wikimedia.org/r/993220

TheDJ subscribed.

Re-opening, to remember that it is still broken after the changes in T141490

Change 993220 merged by jenkins-bot:

[mediawiki/extensions/ConfirmEdit@master] captca.py: Fix PIL 10 support again

https://gerrit.wikimedia.org/r/993220

Wasn’t it fixed by ^

No, check the review comments:

“in map
return self._map_async(func, iterable, mapstar, chunksize).get()
File "/opt/homebrew/Cellar/python@3.11/3.11.7_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/pool.py", line 774, in get
raise self._value
ValueError: y1 must be greater than or equal to y0

“I'd say this is good to fix one part of the problem but we need another patch for the second fix. Does that sound good to you?”

We need add a comparison between draw points and swap them if needed. That's straightforward if anyone is willing to take a look

Change 1004755 had a related patch set uploaded (by Reedy; author: Reedy):

[mediawiki/extensions/ConfirmEdit@master] captcha.py: Swap x0/x1 and y0/y1 values before d.arc() call

https://gerrit.wikimedia.org/r/1004755

@Ladsgroup I don't think this is what the intent was right ?

image_e670453b_fde1b41bcdd829ec.png (73×255 px, 3 KB)

is it all cases? If not, then meh if it is, then we should do something

So trying to use the script again myself locally...

Generating 100 CAPTCHA images separated in 100 image(s) per chunk run by 1 threads...
multiprocessing.pool.RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/usr/lib/python3.10/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "/usr/lib/python3.10/multiprocessing/pool.py", line 48, in mapstar
    return list(map(*args))
  File "/home/reedy/captchas/captcha.py", line 279, in run_in_thread
    gen_captcha(word, font, fontsize, os.path.join(opts.output, filename))
  File "/home/reedy/captchas/captcha.py", line 126, in gen_captcha
    d.arc(
  File "/home/reedy/.local/lib/python3.10/site-packages/PIL/ImageDraw.py", line 143, in arc
    self.draw.draw_arc(xy, start, end, ink, width)
ValueError: y1 must be greater than or equal to y0
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/reedy/captchas/captcha.py", line 426, in <module>
    p.map(run_in_thread, data)
  File "/usr/lib/python3.10/multiprocessing/pool.py", line 367, in map
    return self._map_async(func, iterable, mapstar, chunksize).get()
  File "/usr/lib/python3.10/multiprocessing/pool.py", line 774, in get
    raise self._value
ValueError: y1 must be greater than or equal to y0

If I grab the version from https://gerrit.wikimedia.org/r/c/mediawiki/extensions/ConfirmEdit/+/1004755, it then runs fine without issue

Screenshot 2024-07-19 at 15.20.56.png (676×1 px, 132 KB)

Any blurring etc shown is just macos being weird, they're not blurry when viewed individually...

This is with Pillow 9.5.0... So the bug for ValueError: y1 must be greater than or equal to y0 is maybe more python version related?

Python 3.10.12

If I explicitly install Pillow=10.4.0, and regenerate images...

Screenshot 2024-07-19 at 15.27.49.png (844×1 px, 171 KB)

And then vaguely compared against a random one served by WMF production

Screenshot 2024-07-19 at 15.28.25.png (308×376 px, 29 KB)

They don't seem to be dissimilar

@Ladsgroup I don't think this is what the intent was right ?

image_e670453b_fde1b41bcdd829ec.png (73×255 px, 3 KB)

I'm guessing is just a result of random-ness...

Change #1004755 merged by jenkins-bot:

[mediawiki/extensions/ConfirmEdit@master] captcha.py: Swap x0/x1 and y0/y1 values before d.arc() call

https://gerrit.wikimedia.org/r/1004755

Change #1055575 had a related patch set uploaded (by Reedy; author: Reedy):

[mediawiki/extensions/ConfirmEdit@REL1_42] captcha.py: Swap x0/x1 and y0/y1 values before d.arc() call

https://gerrit.wikimedia.org/r/1055575

Change #1055575 merged by jenkins-bot:

[mediawiki/extensions/ConfirmEdit@REL1_42] captcha.py: Swap x0/x1 and y0/y1 values before d.arc() call

https://gerrit.wikimedia.org/r/1055575

Change #1069252 had a related patch set uploaded (by Reedy; author: Reedy):

[mediawiki/extensions/ConfirmEdit@REL1_41] captcha.py: Swap x0/x1 and y0/y1 values before d.arc() call

https://gerrit.wikimedia.org/r/1069252

Change #1069252 abandoned by Reedy:

[mediawiki/extensions/ConfirmEdit@REL1_41] captcha.py: Swap x0/x1 and y0/y1 values before d.arc() call

https://gerrit.wikimedia.org/r/1069252