Page MenuHomePhabricator

captcha.py: Gracefully handle output dir not existing
Closed, ResolvedPublic

Description

reedy@ubuntu64-web-esxi:/var/www/wiki/mediawiki/extensions/ConfirmEdit$ python3 captcha.py --wordlist=~/words --badwordlist=~/badwords --key='foo' --output=/tmp/captchas --font=/usr/share/fonts/truetype/freefont/FreeMonoBoldOblique.ttf --verbose --fill=1000
Traceback (most recent call last):
  File "/var/www/wiki/mediawiki/extensions/ConfirmEdit/captcha.py", line 436, in <module>
    count = max(0, fill - len(os.listdir(output)))
                              ^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/captchas'
reedy@ubuntu64-web-esxi:/var/www/wiki/mediawiki/extensions/ConfirmEdit$ mkdir /tmp/captchas

Event Timeline

Reedy triaged this task as Low priority.Jun 2 2025, 1:48 PM

The behaviour is inconsistent between specifying --fill and not:

python3 /srv/mediawiki/php-1.45.0-wmf.3/extensions/ConfirmEdit/captcha.py --wordlist=/tmp/words --badwordlist=/tmp/badwords --key='foo' --output=/tmp/captchas --font=/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf --verbose --fill=1000
Traceback (most recent call last):
  File "/srv/mediawiki/php-1.45.0-wmf.3/extensions/ConfirmEdit/captcha.py", line 421, in <module>
    count = max(0, fill - len(os.listdir(output)))
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/captchas'
www-data@b386d95fae9d:/$ python3 /srv/mediawiki/php-1.45.0-wmf.3/extensions/ConfirmEdit/captcha.py --wordlist=/tmp/words --badwordlist=/tmp/badwords --key='foo' --output=/tmp/captchas --font=/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf --verbose 
Generating 20 CAPTCHA images separated in 20 image(s) per chunk run by 1 threads...
[...]
image_a3336939_ad9b6da10e44bb26.png

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

[mediawiki/extensions/ConfirmEdit@master] captcha.py: Check if output dir exists, and attempt to create it (else error)

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

^ Just do some checking when we grab the option

Krinkle assigned this task to Reedy.
Krinkle subscribed.

Hardening after captcha incident on June 2, 2025, ref T388531#10875132.

Change #1152753 merged by jenkins-bot:

[mediawiki/extensions/ConfirmEdit@master] captcha.py: Check if output dir exists, and attempt to create it (else error)

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

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

[mediawiki/extensions/ConfirmEdit@REL1_43] captcha.py: Check if output dir exists, and attempt to create it (else error)

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

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

[mediawiki/extensions/ConfirmEdit@REL1_44] captcha.py: Check if output dir exists, and attempt to create it (else error)

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

Change #1152822 merged by jenkins-bot:

[mediawiki/extensions/ConfirmEdit@REL1_44] captcha.py: Check if output dir exists, and attempt to create it (else error)

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

Change #1152821 merged by jenkins-bot:

[mediawiki/extensions/ConfirmEdit@REL1_43] captcha.py: Check if output dir exists, and attempt to create it (else error)

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

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

[mediawiki/extensions/ConfirmEdit@wmf/1.45.0-wmf.3] captcha.py: Check if output dir exists, and attempt to create it (else error)

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

Change #1153593 merged by jenkins-bot:

[mediawiki/extensions/ConfirmEdit@wmf/1.45.0-wmf.3] captcha.py: Check if output dir exists, and attempt to create it (else error)

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

Mentioned in SAL (#wikimedia-operations) [2025-06-04T12:18:22Z] <reedy@deploy1003> Started scap sync-world: Backport for [[gerrit:rLPRI1153591423f9|GenerateFancyCaptchas: Handle captcha.py not generating any captchas, but not erroring (T388531)]], [[gerrit:1153592|captcha.py: Expand variables and user in filenames (T395810)]], [[gerrit:1153593|captcha.py: Check if output dir exists, and attempt to create it (else error) (T395804)]], [[gerrit:1153595|captcha.py: Bail out if no words were read

Mentioned in SAL (#wikimedia-operations) [2025-06-04T12:20:31Z] <reedy@deploy1003> reedy: Backport for [[gerrit:rLPRI1153591423f9|GenerateFancyCaptchas: Handle captcha.py not generating any captchas, but not erroring (T388531)]], [[gerrit:1153592|captcha.py: Expand variables and user in filenames (T395810)]], [[gerrit:1153593|captcha.py: Check if output dir exists, and attempt to create it (else error) (T395804)]], [[gerrit:1153595|captcha.py: Bail out if no words were read from wordlist (T3

Mentioned in SAL (#wikimedia-operations) [2025-06-04T12:28:13Z] <reedy@deploy1003> Finished scap sync-world: Backport for [[gerrit:rLPRI1153591423f9|GenerateFancyCaptchas: Handle captcha.py not generating any captchas, but not erroring (T388531)]], [[gerrit:1153592|captcha.py: Expand variables and user in filenames (T395810)]], [[gerrit:1153593|captcha.py: Check if output dir exists, and attempt to create it (else error) (T395804)]], [[gerrit:1153595|captcha.py: Bail out if no words were rea