Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed ZeroDivisionError when UA contains punctuation only #36

Conversation

anatoliifetisov
Copy link
Contributor

There's an edge case when alphabetic_chars / len(app_no_punc) < threshold fails with ZeroDivisionError. It's extremely rare in real-world data (as in "couple of dozens per hundreds of millions"-rare), but quite destructive nevertheless.
One of the inputs that cause this is "%7C%7C%27", which decodes into "||'" and leads (after punctuation stripping) to 0/0 evaluation.

Not sure if an empty string should result in True or False to be returned, but since True effectively forces the whole thing to be discarded (and such strings should definitely be discarded) it makes more sense to me.

@anatoliifetisov
Copy link
Contributor Author

anatoliifetisov commented Dec 18, 2020

Another example of a useragent that breaks stuff is "Mozilla/5.0 (Linux; Android 5.1.1; LGLS751 Build/????? ?/ ????????? ???????_??:-775296273) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.93 Mobile Safari/537.36", ZeroDivisionError happens when the parser is trying to figure out secondary client data.

@thinkwelltwd thinkwelltwd merged commit 9eb4289 into thinkwelltwd:master Dec 23, 2021
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.

None yet

2 participants