Skip to content

Guard against edge-case crashes in bot.php - #42

Open
somethingwithproof wants to merge 3 commits into
cluebotng:mainfrom
somethingwithproof:fix-edge-case-crashes
Open

Guard against edge-case crashes in bot.php#42
somethingwithproof wants to merge 3 commits into
cluebotng:mainfrom
somethingwithproof:fix-edge-case-crashes

Conversation

@somethingwithproof

@somethingwithproof somethingwithproof commented Feb 13, 2026

Copy link
Copy Markdown

Summary

Ran into a few spots where unexpected input from the API or wiki templates
can crash the bot or silently corrupt page content. All fixes are defensive
checks on existing code — no new features, no behavioral changes to the
normal archiving path.

  • splitintosections(): initialize $header so pages that start with a
    section heading don't write null into the archived page
  • namespacetoid(): return null for namespaces not in the lookup table
    instead of triggering an undefined array key warning
  • doarchive(): guard $rev access after the revision-walking foreach,
    since an empty API response skips the loop body and leaves it unset
  • doarchive(): cap the archive-size search loop at 1000 iterations —
    previously it could spin forever if every archive page exceeded the limit
  • doarchive(): skip malformed transformheader entries that are missing
    the === delimiter instead of reading an undefined offset

Test plan

  • Read through each change and confirmed it only affects the error/edge path
  • vendor/bin/phpunit on the full suite (pending — depends on Fix bugs in bot.php and add PHPUnit test suite #41 for test harness)
  • Deploy to staging and verify a normal archiving cycle completes

@somethingwithproof

Copy link
Copy Markdown
Author

Stripped the CI workflow changes per the feedback on bot#45 — this PR now only contains the bot.php defensive fixes.

somethingwithproof and others added 3 commits April 10, 2026 17:37
- Reduce CI permissions from write to read-only for lint jobs
- Pin GitHub Actions to specific SHAs to prevent supply chain attacks
- Add composer audit step for dependency vulnerability scanning

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
- Init $header before use in splitintosections() — pages starting
  with a heading would leave it unset, writing null into the page
- Return null from namespacetoid() for unknown namespaces instead
  of hitting an undefined array key
- Check $rev is set after the revision-walking foreach, since an
  empty API response leaves it undefined
- Cap the archive-size while loop at 1000 iterations so it can't
  spin forever if every archive page is over the limit
- Skip malformed transformheader entries missing the === delimiter
  instead of reading past the end of the explode result
- Use non-greedy match in strip_comments so multiple HTML comments
  on one line don't eat the text between them
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant