Marshal serialization behavior when class namespaces change
0 reputation · 10 Aug 2022, 01:30 UTC
Ruby's Marshal module serializes objects into a binary stream that embeds class names directly, making the stream fragile to any subsequent rename or namespace move of those classes. When maintaining long‑term backups, developers face the risk that a Marshal.load call will raise ArgumentError or TypeError if the target class definition has changed, potentially corrupting restored data. The goal is to evaluate whether Marshal can be extended with a lightweight versioning header that would enable detection of schema mismatches before object instantiation, without breaking existing streams or introducing security concerns.
What trade‑offs would a version header impose on stream size and parsing speed? How could such a header be designed to remain compatible with Marshal streams produced by older Ruby versions? Would the addition require a new Marshal API or could it be accommodated through existing extension mechanisms?