Skip to content

data corruption when Encoding.default_internal is UTF-8 #214

Description

@voidlily

It looks like in 5918547, we're now using Encoding.default_internal if set. Rails sets Encoding.default_internal = Encoding::UTF_8 at startup time. This means that with gpgme 2.0.26, there's data corruption in the resulting file if encrypted from a Rails app.

Seeing as that commit was originally to fix #113, I'm now unsure if that was the correct fix given what can happen now if Encoding.default_internal is set to something that isn't binary.

repro

# setting Encoding.default_internal to utf-8 emulates what rails does
Encoding.default_internal = Encoding::UTF_8
require 'gpgme'

plaintext_path, recipient, outfile_path = ARGV

infile = File.open(plaintext_path, 'r')
outfile = File.open(outfile_path, 'wb')
GPGME::Crypto.new.encrypt(infile, recipients: recipient, output: outfile, always_trust: true)
outfile.close
ruby repro.rb plaintext.txt test@example.com test.gpg
❯ file *.gpg
output_2.0.24.gpg: PGP ECDH Public-Key Encrypted Session Key - keyid: AB4977DD 83722AD2
output_2.0.26.gpg: data
test.gpg:          data

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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