[ruby-core:113041] [Ruby master Bug#19558] str.dump.undump crashes when str contains both Unicode and ASCII control characters
From:
"ikaronen-relex (Ilmari Karonen) via ruby-core" <ruby-core@...>
Date:
2023-03-29 13:47:48 UTC
List:
ruby-core #113041
Issue #19558 has been reported by ikaronen-relex (Ilmari Karonen).
----------------------------------------
Bug #19558: str.dump.undump crashes when str contains both Unicode and ASCII control characters
https://bugs.ruby-lang.org/issues/19558
* Author: ikaronen-relex (Ilmari Karonen)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.3.0dev (2023-03-29T10:20:29Z master 02ecdf85c5) [x86_64-darwin21]
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
Recently, as a result of a question I asked on Stack Overflow (https://stackoverflow.com/q/75866159), I learned about the existence of String#dump and String#undump. However, I also found what seems like a bug in them, in that apparently dumping and then undumping a string containing a sufficiently diverse selection of characters (such as at least one ASCII C0 control character and at least one non-ASCII Unicode character) causes the undump to raise a RuntimeError.
Specifically, evaluating e.g. any of the following expressions:
"\u0000\uFFFF".dump.undump
"\u0001\uABCD".dump.undump
"\u007F\u0080".dump.undump
raises a RuntimeError with the message "hex escape and Unicode escape are mixed". This contradicts the documentation of String#undump, which says that it "does the inverse of String#dump."
The behavior is the same on all Ruby versions I have tested this on, including master (3.3.0), 2.6.10 and JRuby 9.3.10.0.
The obvious fix would be to simply remove the check for mixed hex and Unicode escape sequences, essentially reverting https://github.com/ruby/ruby/commit/05d1d29d1f4a87620371463d8c7942e170be031f. However, as I don't understand why the check is there in the first place, I'm also not sure if removing it could somehow have some unwanted consequences.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- [email protected]
To unsubscribe send an email to [email protected]
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/