Skip to content

Conversation

@kennedn
Copy link

@kennedn kennedn commented Feb 20, 2023

There is a 128kb hard coded limit by default in the linux kernel for the max length of a single argument (MAX_ARG_STRLEN).

The open_config_page() function in the BrowserController object can run into this if the generated app configuration URL is sufficiently large. This is because the webbrowser module will just pass the provided URL as a command line argument to the selected browser.

This can be worked around by writing the url out to a temporary file instead and wrapping it in a client side redirect (<meta http-equiv="refresh" content="0;url={}/>).

I wrote a small script to show the error and prove my solution:

from pebble_tool.util.browser import BrowserController

def handle_config_close(query):
  print(query)

with open("url.txt") as f:
  test_url = f.read()
browser = BrowserController()
browser.open_config_page(test_url, handle_config_close)

The contents of the test url (url.txt) are ~145kb large:
url.txt

Output before changing open_config_page:

❯ python2 browser_test.py
Traceback (most recent call last):
  File "browser_test.py", line 9, in <module>
    browser.open_config_page(test_url, handle_config_close)
  File "/home/kennedn/Projects/pebble-tool/pebble_tool/util/browser.py", line 24, in open_config_page
    webbrowser.open_new(url)
  File "/usr/lib/python2.7/webbrowser.py", line 66, in open_new
    return open(url, 1)
  File "/usr/lib/python2.7/webbrowser.py", line 61, in open
    if browser.open(url, new, autoraise):
  File "/usr/lib/python2.7/webbrowser.py", line 275, in open
    success = self._invoke(args, True, autoraise)
  File "/usr/lib/python2.7/webbrowser.py", line 238, in _invoke
    stderr=inout, preexec_fn=setsid)
  File "/usr/lib/python2.7/subprocess.py", line 394, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1047, in _execute_child
    raise child_exception
OSError: [Errno 7] Argument list too long

Output after switching over to the tempfile method:

python2 browser_test.py

The browser then proceeds to open the configuration page:

Screenshot from 2023-02-20 21-13-01

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