Skip to content

Improper usage of PNG tEXt chunks in parameters #1535

@enslo

Description

@enslo

What happened?

Non-Latin-1 characters in the "parameters" metadata are being stored directly within a tEXt chunk. This violates the PNG specification (ISO-8859-1) and results in character corruption (mojibake) when the file is read by standard-compliant parsers.

Expected

When the parameters chunk contains non-Latin-1 characters:

  • The parameters should be stored in an iTXt chunk.
  • OR
  • Any non-Latin-1 characters should be Unicode-escaped if they are kept within a tEXt chunk.

Bug

  • Non-Latin-1 characters are stored directly as raw bytes in the tEXt chunk without escaping.
    • This violates the PNG specification, which requires tEXt chunk content to be ISO-8859-1 (Latin-1).
    • As a result, character corruption (mojibake) occurs in standard-compliant parsers (e.g., テスト becomes ã��ã�¹ã��).

Steps to reproduce

  1. Generate an image using a prompt that contains non-Latin-1 characters (e.g., テスト).
  2. Inspect the parameters chunk of the generated PNG file.

Sidenote

  • ComfyUI addresses this by using Unicode escaping while maintaining the use of tEXt chunks.
  • Most other tools (especially A1111 derivatives, for compatibility with the parameters chunk content) switch from tEXt to iTXt chunks when the content includes non-Latin-1 characters.

I noticed this while developing my @enslo/sd-metadata library. Technically, this might be a minor point, but I wanted to let you know for better specification compliance.

Version

2.16.0-dev.1+597a23f

What Operating System are you using?

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions