Skip to content

encoding issues when clearsigning UTF-8 data #113

@ice799

Description

@ice799

If you GPG clearsign some UTF-8 encoded data, ruby-gpgme will raise in the IOCallbacks:

Encoding::UndefinedConversionError: "\xC3" from ASCII-8BIT to UTF-8
from /usr/lib/x86_64-linux-gnu/ruby/gems/2.4.0/gems/gpgme-2.0.2/lib/gpgme/io_callbacks.rb:12:in `write'
/usr/lib/x86_64-linux-gnu/ruby/gems/2.4.0/gems/gpgme-2.0.2/lib/gpgme/ctx.rb:417:in `gpgme_op_sign'
/usr/lib/x86_64-linux-gnu/ruby/gems/2.4.0/gems/gpgme-2.0.2/lib/gpgme/ctx.rb:417:in `sign'
...

The issue is that write_cb in the C extension does not associate an encoding with the string allocated with rb_str_new so the default is ASCII-8BIT. This string is then passed to IOCallbacks#write as buffer where it will have the ASCII-8BIT encoding associated with it. If the output @io object uses a different encoding, writing the buffer to that @io will raise as seen above.

To fix this, the string in the C extension would ideally at least be associated with the default internal encoding this way the app author can specify which encoding strings should be and everything will work as planned. Alternatively, you would add a method for library users to set the desired encoding to take precedence over the default internal encoding.

For an example of how to do this, you can check out the YAJL ruby code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions