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

apparent infinite loop with scale=float #11

Closed
abe-winter opened this issue Aug 4, 2022 · 3 comments
Closed

apparent infinite loop with scale=float #11

abe-winter opened this issue Aug 4, 2022 · 3 comments

Comments

@abe-winter
Copy link

Hi! I think there's an infinite loop in to_artistic() when scale is a float. Example:

>>> qr.to_artistic(background='whatever.png', target='qr.png', scale=4.5)
^CTraceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../.direnv/python-3.10.4/lib/python3.10/site-packages/qrcode_artistic.py", line 134, in write_artistic
    while scale % 3:
KeyboardInterrupt

I'm using qrcode-artistic==2.1.0, segno==1.5.2

I think this is happening here:
https://github.com/heuer/qrcode-artistic/blob/b93c548/qrcode_artistic.py#L140-L141

as you can see, this loops forever with any non-integer

>>> x = 4.5
>>> for i in range(20):
...  print(x % 3)
...  x += 1
... 
1.5
2.5
0.5
1.5
2.5
0.5

is it reasonable to add a check before the loop which crashes if round(scale) != scale? I'm happy to submit this PR if that's useful to you.

thanks for this library, I love the results

@heuer
Copy link
Owner

heuer commented Aug 4, 2022

Thanks for your report.

You're right, I didn't expect float numbers.

Segno itself deals with this problem (i.e. the PNG serializer) by silently converting the number to an integer int(scale). Probably round(scale) would also have been a good solution, maybe even the better one. I would suggest that the number is simply converted to an integer without throwing an exception. This should then be pointed out in the documentation.

@abe-winter
Copy link
Author

'always round' sounds good to me

do you want me to send this PR?

heuer added a commit that referenced this issue Aug 4, 2022
Handle multiple Pillow versions, use Python 3.10 as default test suite runner
@heuer
Copy link
Owner

heuer commented Aug 4, 2022

I implemented a solution: Convert scale to int since it is the default behaviour of Segno.

I will publish a new release in the next few days. Thanks for finding the bug!

@heuer heuer closed this as completed Aug 4, 2022
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

No branches or pull requests

2 participants