[#115984] [Ruby master Misc#20107] Update required Oracle Solaris Studio version to 12.5 — "kddnewton (Kevin Newton) via ruby-core" <ruby-core@...>

Issue #20107 has been reported by kddnewton (Kevin Newton).

7 messages 2024/01/02

[#115985] [Ruby master Feature#20108] Introduction of Happy Eyeballs Version 2 (RFC8305) in Socket.tcp — "shioimm (Misaki Shioi) via ruby-core" <ruby-core@...>

Issue #20108 has been reported by shioimm (Misaki Shioi).

14 messages 2024/01/02

[#116028] [Ruby master Feature#20152] mkmf / extconf: Add a proper way to not compile the extension — "byroot (Jean Boussier) via ruby-core" <ruby-core@...>

Issue #20152 has been reported by byroot (Jean Boussier).

21 messages 2024/01/05

[#116039] [Ruby master Bug#20154] aarch64: configure overrides `-mbranch-protection` if it was set in CFLAGS via environment — "jprokop (Jarek Prokop) via ruby-core" <ruby-core@...>

Issue #20154 has been reported by jprokop (Jarek Prokop).

11 messages 2024/01/05

[#116041] [Ruby master Bug#20155] Using value of rb_fiber_scheduler_current() crashes Ruby — "paddor (Patrik Wenger) via ruby-core" <ruby-core@...>

Issue #20155 has been reported by paddor (Patrik Wenger).

12 messages 2024/01/05

[#116065] [Ruby master Feature#20160] rescue keyword for case expressions — "lloeki (Loic Nageleisen) via ruby-core" <ruby-core@...>

Issue #20160 has been reported by lloeki (Loic Nageleisen).

9 messages 2024/01/08

[#116083] [Ruby master Feature#20163] Introduce #bit_count method on Integer — "garrison (Garrison Jensen) via ruby-core" <ruby-core@...>

Issue #20163 has been reported by garrison (Garrison Jensen).

25 messages 2024/01/08

[#116114] [Ruby master Bug#20169] `GC.compact` can raises `EFAULT` on IO — "ko1 (Koichi Sasada) via ruby-core" <ruby-core@...>

Issue #20169 has been reported by ko1 (Koichi Sasada).

14 messages 2024/01/09

[#116129] [Ruby master Bug#20172] Socket.addrinfo failing randomly — "mwaldvogel (Michael Waldvogel) via ruby-core" <ruby-core@...>

Issue #20172 has been reported by mwaldvogel (Michael Waldvogel).

9 messages 2024/01/09

[#116182] [Ruby master Bug#20180] Inconsistent evaluation of `**{}` depending on position in array — "ozydingo (Andrew Schwartz) via ruby-core" <ruby-core@...>

Issue #20180 has been reported by ozydingo (Andrew Schwartz).

8 messages 2024/01/12

[#116203] [Ruby master Bug#20185] String#ascii_only? buggy in ruby 3.3 — "chucke (Tiago Cardoso) via ruby-core" <ruby-core@...>

SXNzdWUgIzIwMTg1IGhhcyBiZWVuIHJlcG9ydGVkIGJ5IGNodWNrZSAoVGlhZ28gQ2FyZG9zbyku

7 messages 2024/01/14

[#116223] [Ruby master Bug#20188] `Module#const_source_location` returns wrong information when real constant was defined but autoload is still ongoing — "byroot (Jean Boussier) via ruby-core" <ruby-core@...>

Issue #20188 has been reported by byroot (Jean Boussier).

32 messages 2024/01/16

[#116315] [Ruby master Misc#20193] DevMeeting-2024-02-14 — "mame (Yusuke Endoh) via ruby-core" <ruby-core@...>

Issue #20193 has been reported by mame (Yusuke Endoh).

16 messages 2024/01/19

[#116347] [Ruby master Bug#20197] Postponed job invocations are significantly reduced in Ruby 3.3 — "osyoyu (Daisuke Aritomo) via ruby-core" <ruby-core@...>

Issue #20197 has been reported by osyoyu (Daisuke Aritomo).

8 messages 2024/01/20

[#116370] [Ruby master Bug#20203] `TestEnumerable` test failures with GCC 14 — "vo.x (Vit Ondruch) via ruby-core" <ruby-core@...>

Issue #20203 has been reported by vo.x (Vit Ondruch).

13 messages 2024/01/22

[#116382] [Ruby master Feature#20205] Enable `frozen_string_literal` by default — "byroot (Jean Boussier) via ruby-core" <ruby-core@...>

Issue #20205 has been reported by byroot (Jean Boussier).

77 messages 2024/01/23

[#116395] [Ruby master Bug#20207] Segmentation fault for a regexp containing positive and negative lookaheads — "Sundeep (Sundeep Agarwal) via ruby-core" <ruby-core@...>

Issue #20207 has been reported by Sundeep (Sundeep Agarwal).

7 messages 2024/01/24

[#116399] [Ruby master Bug#20208] Net::HTTP errors with Errno::EAFNOSUPPORT when setting local_host with Addrinfo — "jprokop (Jarek Prokop) via ruby-core" <ruby-core@...>

Issue #20208 has been reported by jprokop (Jarek Prokop).

9 messages 2024/01/24

[#116435] [Ruby master Misc#20210] Invalid source encoding raises ArgumentError, not SyntaxError — "kddnewton (Kevin Newton) via ruby-core" <ruby-core@...>

Issue #20210 has been reported by kddnewton (Kevin Newton).

8 messages 2024/01/25

[#116456] [Ruby master Feature#20215] Introduce `IO#readable?` — "ioquatix (Samuel Williams) via ruby-core" <ruby-core@...>

Issue #20215 has been reported by ioquatix (Samuel Williams).

17 messages 2024/01/26

[#116460] [Ruby master Bug#20218] aset/masgn/op_asgn with keyword arguments — "jeremyevans0 (Jeremy Evans) via ruby-core" <ruby-core@...>

Issue #20218 has been reported by jeremyevans0 (Jeremy Evans).

18 messages 2024/01/27

[#116491] [Ruby master Bug#20225] Inconsistent behavior of regex matching for a regex has a null loop — "make_now_just (Hiroya Fujinami) via ruby-core" <ruby-core@...>

Issue #20225 has been reported by make_now_just (Hiroya Fujinami).

10 messages 2024/01/30

[#116493] [Ruby master Bug#20226] Inconsistent Sort results on 3.3.0 compared to previous versions — "omerby (Omer Ben Yosef) via ruby-core" <ruby-core@...>

Issue #20226 has been reported by omerby (Omer Ben Yosef).

14 messages 2024/01/30

[ruby-core:116345] [Ruby master Feature#20196] Proposal: Binary data literal

From: "ziggythehamster (Keith Gable) via ruby-core" <ruby-core@...>
Date: 2024-01-20 02:59:58 UTC
List: ruby-core #116345
Issue #20196 has been reported by ziggythehamster (Keith Gable).

----------------------------------------
Feature #20196: Proposal: Binary data literal
https://bugs.ruby-lang.org/issues/20196

* Author: ziggythehamster (Keith Gable)
* Status: Open
* Priority: Normal
----------------------------------------
I sometimes find myself needing to write some bytes in a Ruby string literal, and this experience leaves a lot to be desired:

* Bare strings don't work (potential for encoding corruption unless you remember to `.force_encoding` and never copy-paste just the literal into somewhere else) and are not particularly pleasant given all of the backslashes
* Wrapping this in `String.new("\x89PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x00`\x00\x00\x00`\b\x06\x00\x00\x00\xE2\x98w8\x00\x000%IDAT", encoding: 'BINARY')` is better, but many tools explode with this because they expect all strings to be valid UTF-8 even if they're an argument to String.new, and it still doesn't have the "beauty" one might expect from Ruby (also it's not frozen unless you also freeze it)
* `["9805e474d0a0a1a0000000d094844425000000060000000680600000002e8977830000035294441445"].pack("h*")` parses in all tools and is less harsh to look at, but if you're writing binary data, you probably want to annotate it

Here's my basic syntax proposal:

```
%b[
  89504e470d0a1a0a # PNG header
  0000000d         # Length = 13 bytes
  49484452         # IHDR chunk
  00000060         # Width = 96px
  00000060         # Height = 96px
  08 06            # 8bpp RGBA
  00 00 00         # deflate / no filter / non-interlaced
]

# => "\x89PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x00`\x00\x00\x00`\b\x06\x00\x00\x00"
```

More formally:

* To match the nibble ordering of a regular string escape, the hex characters are high nibble first (the same as the `H` unpack character).
* It follows the same rules as other percent literals, and I am flexible on what character is used. I chose `b` because `h` could be confusing paired with the `h`/`H` unpack characters and the inverted meaning.
* We could say that high-nibble-first is capitalized and the lower-case version is low-nibble-first, but I imagine most people will want high-nibble-first. We could also say that `%b[]` returns a `String` but `%B[]` returns an `IO::Buffer`, which has greater utility than having the capability of writing low-nibble-first literals
* Whitespace is ignored
* Comments are allowed
* The encoding is always `Encoding::BINARY`
* The resulting string is always frozen (and if `%B[]` means buffer then that is read-only as well)
* a-f can also be written A-F

Things to consider:

* Interpolation could be allowed like normal strings
* Embedding strings could be allowed (example below)
* `?` literals (characters) should be handled identically to how other kinds of strings are embedded if that is allowed
* If interpolation is allowed and you interpolate a number, this should either interpolate `.to_s` as you would expect in a string or raise an error, because there is no unsurprising way to take a number and convert it to one or more bytes
* Strings encoded as `Encoding::BINARY` could have their `.inspect` output use this literal
* When dealing with bitmasks, it's often convenient to write them out in binary instead of hex so the on bits are easier to identify, but there is no syntax for that here that I am fond of... but someone might have an idea. I thought about `.00001111` or `!00001111` with mandatory whitespace before resuming hex characters, but those didn't feel right to me

Example with embedded strings:


```
%b[
  89 "PNG" 0d0a1a0a # PNG header
  0000000d          # Length = 13 bytes
  "IHDR"            # IHDR chunk
  00000060          # Width = 96px
  00000060          # Height = 96px
  08 06             # 8bpp RGBA
  00 00 00          # deflate / no filter / non-interlaced
]
```

Example with interpolation:

```
%b[
  #{png_header}
  #{ihdr = chunk(:ihdr, width: 96, height: 96, bpp: 8, format: :rgba)}
  #{png_crc(ihdr)} # I didn't include this in the other examples but I needed something to demonstrate here
]
```

Other possible alternatives:

* A library (possibly standard library/gem) could have a function like `binary` take a string (potentially a heredoc) and parse it according to the same rules I wrote above. You would have to make the parser strip whitespace and comments, and only hex bytes could be interpolated.
* A new pack/unpack symbol could be created that does the same thing as above, so you could `["hex #comments\netc"].pack("...")`
* You could probably do a lot of this with an array of hex strings and `pack` but it doesn't allow for freeform whitespace and the way you do it is not obvious without reading the docs for `pack` ... and also you allocate a bunch of strings you don't need
* A `Data`-like object more closely related to `IO::Buffer` could be defined that declares the size of things contained within a buffer and then a constant could be written to create an instance of the Data-subclass containing the actual data you want to write out ... but this is a lot of work

Potential users:

* People writing protocol code in Ruby
* People who need to write out magic constants (in my case: the RDB encoding of a Redis value)
* People using something like Metasploit Framework to reverse engineer something
* Tools could e.g. disassemble x86 into a literal with comments showing the assembly mnemonics



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

In This Thread

Prev Next