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

Change request handling to use split instead of regular expressions. #3

Merged
merged 2 commits into from May 18, 2022

Conversation

cthulahoops
Copy link
Contributor

The regular expression fails with a stack overflow for paths of
more than 135 characters. The split also appears to be much faster.

Failing parse:

>>> import re
>>> _REQUEST_RE = re.compile(r"(\S+)\s+(\S+)\s")
>>> _REQUEST_RE.match("GET /" + ("a" * 135) + " whatev")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: maximum recursion depth exceeded

Co-authored-by: Shae Erisson shae@scannedinavian.com

cthulahoops and others added 2 commits May 17, 2022 17:08
The regular expression fails with a stack overflow for paths of
more than 135 characters. The splits also appears to be much faster.

Co-authored-by: Shae Erisson <shae@scannedinavian.com>
@dhalbert
Copy link
Contributor

I don't get the stack overflow error, testing on a random board (nrRF 52840). What board are you testing this on?

@shapr
Copy link
Contributor

shapr commented May 17, 2022

I don't get the stack overflow error, testing on a random board (nrRF 52840). What board are you testing this on?

This fails on the AdaFruit FunHouse running Circuit Python 7.2.5

>>> import re
>>> _REQUEST_RE = re.compile(r"(\S+)\s+(\S+)\s")
>>> _REQUEST_RE.match("GET /" + ("a" * 135) + " whatev")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: maximum recursion depth exceeded
>>> _REQUEST_RE.match("GET /" + ("a" * 134) + " whatev")
<match num=3>

@shapr
Copy link
Contributor

shapr commented May 17, 2022

I don't get the stack overflow error, testing on a random board (nrRF 52840). What board are you testing this on?

Same thing on a MagTag with CircuitPython 7.2.5

Adafruit CircuitPython 7.2.5 on 2022-04-06; Adafruit MagTag with ESP32S2
>>> import re
>>> _REQUEST_RE = re.compile(r"(\S+)\s+(\S+)\s")
>>> _REQUEST_RE.match("GET /" + ("a" * 135) + " whatev")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: maximum recursion depth exceeded
>>> _REQUEST_RE.match("GET /" + ("a" * 134) + " whatev")
<match num=3>

@dhalbert
Copy link
Contributor

I think there is a stack depth issue on ESP32-nn. That is a separate core CircuitPython issue. But I'll review this for its own sake.

Copy link
Contributor

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. I think using the regular expression would generate less garbage, but if it's noticeably faster, that's fine too.

adafruit_httpserver.py Show resolved Hide resolved
Copy link
Contributor

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@dhalbert dhalbert merged commit ca2f648 into adafruit:main May 18, 2022
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request May 19, 2022
Updating https://github.com/adafruit/Adafruit_CircuitPython_HTTPServer to 0.1.3 from 0.1.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_HTTPServer#3 from shapr/http_request_line
  > Update .pre-commit-config.yaml
  > Patch .pre-commit-config.yaml
  > change discord badge
  > Patch: Replaced discord badge image
  > Updated gitignore
  > Update Black to latest.
  > Corrected pylint version
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

3 participants