3 ms·
> arbitrary object deserialization [...] is inherently unsafe Is it always? In a language with side-effects (like Java), maybe, but in something like Haskell,
by TazeTSchnitzel 11y ago
> arbitrary object deserialization [...] is inherently unsafe
Is it always? In a language with side-effects (like Java), maybe, but in something like Haskell, surely it would be completely safe?
- CJefferson 11y agoIn Haskell you could still escape with System.IO.Unsafe at any time. of course you could check your desiralised code isn't doing anything unsafe, but that's fairly easy to do in Java too.
- codygman 11y agoThe way to do so in Haskell is putting "Safe" in the Language section of a cabal file, and it covers other stuff like partial functions IIRC. Are you saying that Java has something similar to SafeHaskell? Are you saying they are nearly the same? If yes to the last one, I feel that might be untrue. It's quite possible I just read through your comment too quickly though.
- CJefferson 11y agoIn Java, it's easy to run code under a SecurityManager, which lets you carefully control exactly what other classes the code can access. This gives you really fine-grained control, and lets you control very carefully what code is doing.
- Filligree 11y agoYes. The binary/cereal libraries are perfectly safe unless there's a bug in the compiler/RTS somewhere.
- barrkel 11y agoThe distinction between file formats and programs is mostly convention rather than semantic. The logical structure of a file parser is almost indistinguishable from that of a language parser, and most file parsers include what is effectively an interpreter to massage the low-level file instructions into something more meaningful in the loading program's domain model. A file format is a program that, when evaluated, constructs an in-memory data structure. The degree to which this is a problem depends on the side effects (if any) of data structure construction, and the set of data structures available to be constructed. And of course how the data structure is used later; if the data structure represents instructions (this is perfectly possible even in pure languages like Haskell) or may behave other than expected with inheritance, more problems ensue. That's all independent of simple bugs in the parser, such as buffer overflows when trusting lengths and offsets embedded in the file, or infinite loops with naive offset chasing.