Skip to content

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

@Alyxion

Description

@Alyxion

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.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions