pteichman / cobe

A Markov chain based text generation library and MegaHAL style chatbot
http://teichman.org/blog/
MIT License
242 stars 51 forks source link

Crash with certain encoding #17

Closed viocar closed 10 years ago

viocar commented 10 years ago

With the latest version of cobe, the program crashes when people use certain characters with certain encodings in IRC.

Example crash 1:

[user] not just lost, he's... JIMMYLOST™ cobe has quit (Read error: Connection reset by peer)

"user" in this case is using the "IRC" encoding, which is apparently ISO-8859-15 with UTF-8 as a fallback. Using the ™ character with UTF-8 as your encoding works fine.

Traceback: http://pastebin.com/D7txeviV

[EDIT] Example crash 2 was my fault. I've fixed it. UTF-8 does not crash it anymore. Example crash 1 is still happening.

I made a tiny modification to bot.py that shouldn't affect the encoding. Line 122 is "bot.start()" in "class Runner". Here's my modified version just in case: http://pastebin.com/eNExv4t9

This issue confuses me because a bot I ran on another channel worked just fine for a while. It was able to handle all encodings and didn't crash. When I restarted the bot, however, it started crashing again. I made no modifications to the code in this time.

pteichman commented 10 years ago

Great report, thanks!

The quickest & easiest fix is to use some fallback encoding support introduced in version 8.7 of the irc lib, and I've updated master to point to the latest (irc==8.9.1). You'll need to update your cobe tree and upgrade irc before running. (pip install irc==8.9.1 perhaps?)

The cobe code you've been running is sensitive to whatever bytes happen to be sent from each user's irc client, and an irc server could even re-encode as utf-8 itself, so I'm not surprised to hear that it crashes in some circumstances and not in others.

In the next few days I'll probably upgrade all of cobe's dependencies and roll a new release to get current. I've assumed you're running from master (since you mentioned bot.py). If you're running from PyPI, that'll get updated on the new release.

viocar commented 10 years ago

That fixed it. Thanks a bunch!

pteichman commented 10 years ago

Great!