ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:110636] [Ruby master Bug#19108] Format routines like pack blindly treat a string as ASCII-encoded
@ 2022-11-07 10:21 chrisseaton (Chris Seaton)
  2022-11-07 12:51 ` [ruby-core:110639] " chrisseaton (Chris Seaton)
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: chrisseaton (Chris Seaton) @ 2022-11-07 10:21 UTC (permalink / raw)
  To: ruby-core

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

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

* 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/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:110639] [Ruby master Bug#19108] Format routines like pack blindly treat a string as ASCII-encoded
  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)
  2022-11-07 14:17 ` [ruby-core:110640] " byroot (Jean Boussier)
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: chrisseaton (Chris Seaton) @ 2022-11-07 12:51 UTC (permalink / raw)
  To: ruby-core

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/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:110640] [Ruby master Bug#19108] Format routines like pack blindly treat a string as ASCII-encoded
  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 ` [ruby-core:110639] " chrisseaton (Chris Seaton)
@ 2022-11-07 14:17 ` byroot (Jean Boussier)
  2022-11-21 13:47 ` [ruby-core:110834] " Eregon (Benoit Daloze)
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: byroot (Jean Boussier) @ 2022-11-07 14:17 UTC (permalink / raw)
  To: ruby-core

Issue #19108 has been updated by byroot (Jean Boussier).


I agree that at the very least the `unknown pack directive` warning should be made non-verbose (displayed even with `$VERBOSE=false`, and would make sense as `ArgumentError`.



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

* 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/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:110834] [Ruby master Bug#19108] Format routines like pack blindly treat a string as ASCII-encoded
  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 ` [ruby-core:110639] " chrisseaton (Chris Seaton)
  2022-11-07 14:17 ` [ruby-core:110640] " byroot (Jean Boussier)
@ 2022-11-21 13:47 ` Eregon (Benoit Daloze)
  2022-11-22  8:27 ` [ruby-core:110850] " nobu (Nobuyoshi Nakada)
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Eregon (Benoit Daloze) @ 2022-11-21 13:47 UTC (permalink / raw)
  To: ruby-core

Issue #19108 has been updated by Eregon (Benoit Daloze).


Agreed, I think it should be ArgumentError since it's otherwise silently ignoring characters in the pack format string.
A non-verbose warning is better than the current state if ArgumentError is deemed too incompatible.

Here is real case where the silent warning caused confusion for `[1].pack('<L')`: https://github.com/oracle/truffleruby/issues/2791

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

* 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/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:110850] [Ruby master Bug#19108] Format routines like pack blindly treat a string as ASCII-encoded
  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)
                   ` (2 preceding siblings ...)
  2022-11-21 13:47 ` [ruby-core:110834] " Eregon (Benoit Daloze)
@ 2022-11-22  8:27 ` nobu (Nobuyoshi Nakada)
  2022-11-22 17:23 ` [ruby-core:110857] " chrisseaton (Chris Seaton)
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: nobu (Nobuyoshi Nakada) @ 2022-11-22  8:27 UTC (permalink / raw)
  To: ruby-core

Issue #19108 has been updated by nobu (Nobuyoshi Nakada).


chrisseaton (Chris Seaton) wrote in #note-1:
> Possibly we should raise an exception if the string is not `ascii_only?`

I think you want to mean "if the string is not ASCII-compatible".

https://github.com/ruby/ruby/pull/6785

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

* 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/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:110857] [Ruby master Bug#19108] Format routines like pack blindly treat a string as ASCII-encoded
  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)
                   ` (3 preceding siblings ...)
  2022-11-22  8:27 ` [ruby-core:110850] " nobu (Nobuyoshi Nakada)
@ 2022-11-22 17:23 ` 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)
  6 siblings, 0 replies; 8+ messages in thread
From: chrisseaton (Chris Seaton) @ 2022-11-22 17:23 UTC (permalink / raw)
  To: ruby-core

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


> I think you want to mean "if the string is not ASCII-compatible".

Can you explain why?

I think a string is only a valid pack format string if it is `ascii_only?` - if it isn't `ascii_only?` then there is a silent warning and the output encoding is changed. We're proposing raising an error up front 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-100218

* 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/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:110864] [Ruby master Bug#19108] Format routines like pack blindly treat a string as ASCII-encoded
  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)
                   ` (4 preceding siblings ...)
  2022-11-22 17:23 ` [ruby-core:110857] " chrisseaton (Chris Seaton)
@ 2022-11-23  2:57 ` alanwu (Alan Wu)
  2022-12-01  8:15 ` [ruby-core:111117] " matz (Yukihiro Matsumoto)
  6 siblings, 0 replies; 8+ messages in thread
From: alanwu (Alan Wu) @ 2022-11-23  2:57 UTC (permalink / raw)
  To: ruby-core

Issue #19108 has been updated by alanwu (Alan Wu).


Checking `ascii_only?` would reject non-ascii comments which are fine:

```ruby
p [2, 89].pack(<<~PACK)
  C # 🚗
  c
PACK
p [2, 89].pack('Cc')
# Same output
```

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

* 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/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:111117] [Ruby master Bug#19108] Format routines like pack blindly treat a string as ASCII-encoded
  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)
                   ` (5 preceding siblings ...)
  2022-11-23  2:57 ` [ruby-core:110864] " alanwu (Alan Wu)
@ 2022-12-01  8:15 ` matz (Yukihiro Matsumoto)
  6 siblings, 0 replies; 8+ messages in thread
From: matz (Yukihiro Matsumoto) @ 2022-12-01  8:15 UTC (permalink / raw)
  To: ruby-core

Issue #19108 has been updated by matz (Yukihiro Matsumoto).


Template strings should be ASCII compatible, exceptions otherwise.

Matz.


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

* 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/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-12-01  8:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [ruby-core:110639] " chrisseaton (Chris Seaton)
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)

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).