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

[🐛 Bug]: ValueError: ZIP does not support timestamps before 1980 #14143

Open
milahu opened this issue Jun 17, 2024 · 7 comments
Open

[🐛 Bug]: ValueError: ZIP does not support timestamps before 1980 #14143

milahu opened this issue Jun 17, 2024 · 7 comments
Labels
C-py help wanted Issues looking for contributions I-defect

Comments

@milahu
Copy link

milahu commented Jun 17, 2024

What happened?

selenium firefox fails to start
if the firefox profile files have timestamp zero = 1970-01-01

with zipfile.ZipFile(fp, "w", zipfile.ZIP_DEFLATED) as zipped:

fix: add strict_timestamps=False (source)

with zipfile.ZipFile(fp, "w", zipfile.ZIP_DEFLATED, strict_timestamps=False) as zipped:

How can we reproduce the issue?

find firefox-profile -print0 |
xargs -0 touch -m --date=1970-01-01T00:00:00+0000

Relevant log output

File "/nix/store/wjlanzvm75kck4nxq0n2mij926ksp3vv-python3.11-selenium-4.17.0/lib/python3.11/site-packages/selenium/webdriver/firefox/webdriver.py", line 69, in __init__
    super().__init__(command_executor=executor, options=options)
  File "/nix/store/wjlanzvm75kck4nxq0n2mij926ksp3vv-python3.11-selenium-4.17.0/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 188, in __init__
    capabilities = options.to_capabilities()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/wjlanzvm75kck4nxq0n2mij926ksp3vv-python3.11-selenium-4.17.0/lib/python3.11/site-packages/selenium/webdriver/firefox/options.py", line 113, in to_capabilities
    opts["profile"] = self._profile.encoded
                      ^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/wjlanzvm75kck4nxq0n2mij926ksp3vv-python3.11-selenium-4.17.0/lib/python3.11/site-packages/selenium/webdriver/firefox/firefox_profile.py", line 160, in encoded
    zipped.write(filename, filename[path_root:])
  File "/nix/store/k3701zl6gmx3la7y4dnflcvf3xfy88kh-python3-3.11.9/lib/python3.11/zipfile.py", line 1795, in write
    zinfo = ZipInfo.from_file(filename, arcname,
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/k3701zl6gmx3la7y4dnflcvf3xfy88kh-python3-3.11.9/lib/python3.11/zipfile.py", line 550, in from_file
    zinfo = cls(arcname, date_time)
            ^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/k3701zl6gmx3la7y4dnflcvf3xfy88kh-python3-3.11.9/lib/python3.11/zipfile.py", line 391, in __init__
    raise ValueError('ZIP does not support timestamps before 1980')
ValueError: ZIP does not support timestamps before 1980

Operating System

nixos linux

Selenium version

4.17.0

What are the browser(s) and version(s) where you see this issue?

firefox

What are the browser driver(s) and version(s) where you see this issue?

firefox any

Are you using Selenium Grid?

No response

Copy link

@milahu, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@titusfortner
Copy link
Member

titusfortner commented Jun 17, 2024

I'm not sure the value of maintaining time stamps vs supporting profiles generated with timestamp zero.

Would you like to make a PR with the value configurable in the constructor or a property of the profile class?

@titusfortner titusfortner added C-py help wanted Issues looking for contributions and removed needs-triaging labels Jun 17, 2024
Copy link

This issue is looking for contributors.

Please comment below or reach out to us through our IRC/Slack/Matrix channels if you are interested.

@iampopovich
Copy link
Contributor

@titusfortner I added a private field to the class with a default value of True. The property can be set to False, as in the case for fixing the current bug. I believe such changes should not break client code that does not use setting a value to the field self._strict_timestamp.

@milahu
Copy link
Author

milahu commented Jun 21, 2024

thanks for the patch

can we change the default to self._strict_timestamp = False?
i guess no one will care about pre-1980 timestamps in a firefox profile zip ...

    @property
    def encoded(self) -> str:
        """Updates preferences and creates a zipped, base64 encoded string of
        profile directory."""
        if self._desired_preferences:
            self.update_preferences()
        fp = BytesIO()
        with zipfile.ZipFile(fp, "w", zipfile.ZIP_DEFLATED) as zipped:
            path_root = len(self.path) + 1  # account for trailing slash
            for base, _, files in os.walk(self.path):
                for fyle in files:
                    filename = os.path.join(base, fyle)
                    zipped.write(filename, filename[path_root:])
        return base64.b64encode(fp.getvalue()).decode("UTF-8")

@iampopovich
Copy link
Contributor

@milahu @titusfortner I changed the default value to False
I believe that the behavior in the client code will not change at all, because until the current changes, users could not directly pass the argument value or influence it in any way. This means that after the current pull request, this bug will be fixed - this is what we are aiming for. However, if they set the flag self_strict_timestamps = True, the bug will reoccur - this is the expected behavior.

@titusfortner
Copy link
Member

added my comments to the PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-py help wanted Issues looking for contributions I-defect
Projects
None yet
Development

No branches or pull requests

3 participants