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

IMGKit.to_img crashes when setting mode to quiet and receiving the image in-memory #85

Open
Alyxion opened this issue Jul 15, 2022 · 0 comments
Assignees
Labels

Comments

@Alyxion
Copy link

Alyxion commented Jul 15, 2022

Describe the bug
When imgkit.from_string is called with "--quiet" being passed as argument and the result data is retrieved as in-memory image, so from_string's second parameter set to false the function "to_img" will raise an UnicodeDecodeError exception due to the stderr = stderr or stdout statement. It will cause the image to be stored in stderr which will fail just in the line below when .decode("utf-8") is executed on the binary data.

To Reproduce
Call imgkit.from_string("hello world", False, options) with options defining {"format": "png", "quiet": None}.
Code will crash in line 242 at stderr = stderr.decode("utf-8") of imgkit.py because stderror will contain the png's byte data which can not be decoded.

Expected behavior
No exception should be raised.

Environment

  • OS: Ubuntu 20.02
  • IMGkit Version 1.1.
  • wkhtmltopdf Version wkhtmltoimage 0.12.6 (with patched qt)

Additional context
Overriding the lines with 43-45 with

    stdout, stderr = result.communicate(input=string)
    stderr = stderr.decode("utf-8") if stderr else ""
    exit_code = result.returncode

fixed the issue for me.

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

No branches or pull requests

2 participants