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

Stop reading when EPS line becomes too long #6897

Merged
merged 1 commit into from
Jan 18, 2023
Merged

Conversation

radarhere
Copy link
Member

Resolves #6877

Using the following code to check speed (based on test_timeout()),

import time
import pytest
from PIL import Image
Image.init()
with open("Tests/images/timeout-d675703545fee17acab56e5fec644c19979175de.eps", "rb") as f:
    start = time.time()
    with pytest.raises(Image.UnidentifiedImageError):
        with Image.open(f):
            pass
    print("Time taken", time.time() - start)

I get

Time taken 0.07753515243530273

In EpsImagePlugin, after each time fp.readline() is run, an error is raised if fp.readline().strip("\r\n") is longer than 255 characters. So if Pillow isn't going to use the rest of that data, we can stop reading when the line becomes too long.

Applying that change, the speed test gives

Time taken 0.0006549358367919922

That's 118 times faster. This should be sufficient to stop intermittent timeouts in our CIs.

@hugovk hugovk merged commit 876b9f4 into python-pillow:main Jan 18, 2023
@hugovk
Copy link
Member

hugovk commented Jan 18, 2023

Thanks!

@radarhere radarhere deleted the eps branch January 18, 2023 11:06
@radarhere
Copy link
Member Author

This was later reverted by #6879

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Flaky test: Tests/test_file_eps.py::test_timeout
2 participants