ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "chrisseaton (Chris Seaton)" <noreply@ruby-lang.org>
To: ruby-core@neon.ruby-lang.org
Subject: [ruby-core:110639] [Ruby master Bug#19108] Format routines like pack blindly treat a string as ASCII-encoded
Date: Mon, 07 Nov 2022 12:51:33 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-99977.20221107125133.8671@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-19108.20221107102129.8671@ruby-lang.org

Issue #19108 has been updated by chrisseaton (Chris Seaton).


Possibly we should raise an exception if the string is not `ascii_only?`

----------------------------------------
Bug #19108: Format routines like pack blindly treat a string as ASCII-encoded
https://bugs.ruby-lang.org/issues/19108#change-99977

* Author: chrisseaton (Chris Seaton)
* Status: Open
* Priority: Normal
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
Format routines like pack and unpack blindly treat a string as ASCII-encoded, even if they aren't ASCII or ASCII-compatible.

I tried to construct code that was misleading using ASCII-incompatible-encodings but couldn't do it in practice (no ASCII-incompatible encodings have a pack directive ASCII byte that is encoded as a printable character.)

But I could demonstrate at least some strange behaviour:

```
p ['foo'].pack('u').encoding # => #<Encoding:US-ASCII>
p ['foo'].pack('u'.encode('UTF-32BE')).encoding # => #<Encoding:ASCII-8BIT>
```

This is because the NUL characters in the second one (which aren't really NUL characters - they're part of the directive characters) explicitly trigger the encoding to change to binary.

There is a warning, but the warning is only for unexpected directives. How about disallowing or warning for non-ascii compatible format strings?



-- 
https://bugs.ruby-lang.org/

  reply	other threads:[~2022-11-07 12:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-07 10:21 [ruby-core:110636] [Ruby master Bug#19108] Format routines like pack blindly treat a string as ASCII-encoded chrisseaton (Chris Seaton)
2022-11-07 12:51 ` chrisseaton (Chris Seaton) [this message]
2022-11-07 14:17 ` [ruby-core:110640] " byroot (Jean Boussier)
2022-11-21 13:47 ` [ruby-core:110834] " Eregon (Benoit Daloze)
2022-11-22  8:27 ` [ruby-core:110850] " nobu (Nobuyoshi Nakada)
2022-11-22 17:23 ` [ruby-core:110857] " chrisseaton (Chris Seaton)
2022-11-23  2:57 ` [ruby-core:110864] " alanwu (Alan Wu)
2022-12-01  8:15 ` [ruby-core:111117] " matz (Yukihiro Matsumoto)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-99977.20221107125133.8671@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    --cc=ruby-core@neon.ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).