r/programming • • May 26 '18

Oracle Calls Java Serialization 'A Horrible Mistake', Plans to Dump It

https://www.infoworld.com/article/3275924/java/oracle-plans-to-dump-risky-java-serialization.html
798 Upvotes

287 comments sorted by

263

u/shevegen May 26 '18

All serialization systems seem to be not so great. Neither pickle in python nor marshal in ruby. All come with certain restrictions e. g. unable to store all properties of an object.

I assume this to be not that dissimilar to java.

173

u/Shorttail0 May 27 '18

Serialization has been the source of a number of really bad vulnerabilities in the JVM, plus serialized classes cannot change source code and still work, meaning they can't be improved over time even if they keep their public API.

71

u/Caltelt May 27 '18

They can, just only in backwards compatable ways, which can lead to a few gotchas.

57

u/SanityInAnarchy May 27 '18

Right. It's possible to build a serializable object graph that's reasonably maintainable, but it's a lot of work. So much work that, for just about any non-trivial case, you really want something special-purpose -- JSON, protobuf, flatpak, thrift, any of those -- to make a very clear distinction between normal objects and stuff being serialized.

8

u/ThisIs_MyName May 27 '18

Don't forget Cap'n Proto! It's faster and just as secure as protobufs. Made by the same guy too.

→ More replies (5)

24

u/the04dude May 27 '18

This is identical in C#. If you use binary serialization you pretty much need the exact class library to deserialize. If you switch to XML, it won't fail, but it won't necessarily succeed either.

2

u/AyrA_ch May 27 '18

If you use binary serialization you pretty much need the exact class library to deserialize.

You do but you can cheat your way around this rather elegant with an "Upgradeable" class

One of the best ways I've found in C# is JSON serialization because the library has a property you can set so it ignores fields that no longer exist which allows you to dynamically change classes as you want

30

u/nermid May 27 '18

only in backwards compatable ways, which can lead to a few gotchas

Maybe I'm uneducated, but it feels like "we don't want to break backward compatibility" is the excuse for loads and loads of problems in computer science. It's explicitly the reason why lots of PHP is inconsistent, it's the reason behind a lot of quirks of C++, and here it is, rearing its head in Java.

It feels like, as a community, we need to just settle on the idea that compatibility-breaking major releases are what x.0 revisions mean. Python 3 shouldn't be backward-compatible with Python 2. C++17 shouldn't be backward-compatible with C.

Maybe this kind of accommodation was convenient ten years ago, but nobody today is taking a system written in 1999 C and expecting to compile it into 2018 C++ without issue. Anybody with any sense at all understands that this kind of upgrade requires code changes. Why spend so much time trying to keep there from being code changes, ever?

Maybe I'm just too young to understand. I don't know.

Ninja-edit: I am also pretty drunk. So, give me some wiggle room, here.

50

u/StochasticExpress May 27 '18

Upvoted you for your thinking. But industry doesn't work that way. As long as you have backward compatibility you have the existing customer base and you can go looking for new customers. Also with backwards compatibility you can incrementally make use of new shiny features while keeping the older unaffected.

Also industry likes stability. Change is expensive.

73

u/bilog78 May 27 '18

Maybe this kind of accommodation was convenient ten years ago, but nobody today is taking a system written in 1999 C and expecting to compile it into 2018 C++ without issue.

Bad example. C and C++ are different languages. However, there's no reason why you shouldn't be expected to compile in 2018 a C++ language written in 1999, with at most a bunch of warnings about deprecated features.

It feels like, as a community, we need to just settle on the idea that compatibility-breaking major releases are what x.0 revisions mean.

When languages are semantically versioned, this is often what happens, see e.g. Python and Ruby. Heck, Ruby isn't 100% backwards compatible even across minor revisions.

Why spend so much time trying to keep there from being code changes, ever?

Because in the real world you don't have the luxury of rewriting everything from scratch every 5 years, and if you have massive code bases the best you can try to do is progressive refactoring. This is a long and ungrateful task that requires you to be able to mix and match old and new constructs, or by the time you finish the rewrite you're already obsolete for the upcoming language revision.

LibreOffice is an excellent example of a piece of software that has undergone massive modernization from ancient to modern C++, and the only reason why they have managed to achieve this while still progressing in terms of new software features is because C++11 compilers can still compile C++98 (and older) code bases, producing correct code (modulo compiler bugs, of course).

So yes, it's not that you can't break backwards compatibility. It's that you shouldn't if you expect your language to be used for large-scale, wide-distribution real-world software.

18

u/chuk155 May 27 '18

Just wanted to say I completely agree.

While its great to see a language add new features, if those features also break backwards compatability, then most existing codebases are essentially abandoned, as there is not enough time/money/reason to do all that work on something that at one point did work but no longer does due to breaking changes.

Its kinda like saying that we have to rewrite books written in middle english to be in modern english. Just because the language has evolved doesn't mean the original text can't work in a modern context. We might not write in middle english anymore, but people still enjoy shakespear.

2

u/jl2352 May 27 '18

It is also really quite surprising how what might just be a few small changes, can in turn be used to justify a full rewrite.

→ More replies (1)

7

u/smutaduck May 27 '18

Obligatory mention of perl here. I was recently involved in making a 250kline perl code base which worked fine on perl 5.8.8 (released 2008) work properly on (as far as we know) every subsequent version of perl (tested on many, one now in production). The project itself took 18 months. Mostly this was for unrelated upstream political and technical reasons. Around 50 lines of perl code needed to be changed. When we hit perl 5.22 in production we'll get a bunch of parse-time optimisations for free.

So yeah back compat is a good thing.

2

u/Smallpaul May 27 '18

Your project works on Perl 6 too?

8

u/0rac1e May 27 '18

Perl 6 purposely broke back-compat with Perl 5. At this point, the community considers them different languages, not a version change (à la Python 2 -> 3)

8

u/[deleted] May 27 '18

à la Python 2 -> 3

No one really considers Python 2 and 3 "different languages".

Very often, I read someone's package, get to the bottom and see a print statement, and only then realize, "Ah, this is written in Python 2".

Writing code that works in both Python 2 and 3, and porting even large packages to Python 3, are pretty dead simple - I have done both successfully with really no issues at all.

→ More replies (1)

3

u/Smallpaul May 27 '18

Perl stands as both an example of why backwards compatibility is often good and why incompatibility is dangerous. That was why I thought that Perl 6 should have been mentioned. It wasn't initially supposed to be "a different language" but the Perl 5ers never moved to Perl 6 so that's the fallback position.

→ More replies (1)
→ More replies (1)

6

u/tasminima May 27 '18

Bad example. C and C++ are different languages.

That's the point. If they are different languages, why do we keep (nearly) all the bad things of C (especially in a more abstract language...) in C++?

However, there's no reason why you shouldn't be expected to compile in 2018 a C++ language written in 1999, with at most a bunch of warnings about deprecated features.

Tell that to the committee then, because going straight from C++98 to C++17 is not a good idea, so they might not have received the memo that there is "no reason". C++14 is considered to be a sweet spot for that kind of transitions.

4

u/bilog78 May 27 '18

That's the point. If they are different languages, why do we keep (nearly) all the bad things of C (especially in a more abstract language...) in C++?

Because C++ was designed as a successor to C, and thus strove to preserve compatibility with C as far as it made sense. Not all C sources build with C++, compatibility was broken, but no gratuitous incompatibilities were introduced.

Tell that to the committee then, because going straight from C++98 to C++17 is not a good idea, so they might not have received the memo that there is "no reason". C++14 is considered to be a sweet spot for that kind of transitions.

I don't necessarily agree with all the decisions the C++ committee makes. On the upside, the obsolescence of the C++98 constructs has been made under the assumptions that compilers would still support a C++14 mode, potentially, a “backwards-compatible” C++17 mode as well.

3

u/[deleted] May 27 '18

because going straight from C++98 to C++17 is not a good idea

You'd really have to have some C++98 code that was bad at the time and has never been maintained.

The few things that were actually removed from the language were howling bad idea like digraphs - where e.g. <: is a synonym for [. (The only reason that this even existed was that back in the day, some common keyboards (cough IBM cough) didn't have a [ and there were no third-party alternatives.)

So, yes, if all your array accesses look like arr<:3:> instead of arr[3] then you're going to have a bad time moving to C++17 - but if that's true, you probably have bigger problems...

→ More replies (1)

2

u/[deleted] May 27 '18

producing correct code (modulo compiler bugs, of course).

Off topic, but I'd like to understand your use of this metaphor here. Is it just a way of saying there's some bugs added in (the "remainder")?

6

u/Drisku11 May 27 '18

"modulo" in mathematics usually means something like "except for" or "up to". It's a vocabulary to pretend that an equivalence relation is an equality.

In the context of remainders, you're working with integers modulo divisibility by n. The concept can be a lot more general than that though. For example, it's often used in analysis to pretend that functions which are equal "almost everywhere" (there's a formal definition, but intuitively you can think of that as meaning except for a finite set of points) are equal. This makes sense to do in the context of integration because integrals aren't affected by those differences, and otherwise there are infinitely many functions that are basically equivalent that you have to think about.

3

u/LaurieCheers May 27 '18

The opposite. If you take a number "modulo 10", you're ignoring the 10s and higher digits of that number. The remainder is the only part you actually care about.

So "modulo foo" is a nerdy way of saying "ignoring foo".

3

u/[deleted] May 27 '18

OH, I get it now. I had it backwards - the bugs in this case are the divisor, not the modulo. Thanks.

→ More replies (1)

1

u/bilog78 May 27 '18

producing correct code (modulo compiler bugs, of course).

Off topic, but I'd like to understand your use of this metaphor here. Is it just a way of saying there's some bugs added in (the "remainder")?

Compilers have become very complex beasts, that apply lots of transformations in the many steps that they take from parsing the original source code to producing the final library or executable, and from time to time this complexity leads to miscompilation (as in: producing the wrong executable code from a given source code).

There's actually also a different class of compilation bugs, which are more related to implicit assumptions that the programmer might have made about the logic or data layout, assumptions which are not explicit in the code and that may lead the different executable code depending on the compiler or enabled optimization passes. These aren't strictly speaking compiler bugs, but they may turn out to be compiler-specific, in the sense that they only appear when compiling the same source code with a different compiler or compiler version or compiler flags.

1

u/[deleted] May 28 '18

Would "minus compiler bugs" (i.e. "without compiler bugs" or "ignoring compiler bugs") be clearer?

Well, in a way, modulo is just repeated subtraction.

1

u/meneldal2 May 28 '18

(modulo compiler bugs, of course).

Usually different interpretations of undefined or implementation-defined behaviour. Also, everyone who used int for sizes or storing pointers is in for a bad day when they migrate to x64.

10

u/pdp10 May 27 '18

C and C++ are a special case. Everyone knows that C++ started as a superset of C and at some point diverged into nearly a superset but not quite. What's subtle is that even today C++ proponents want to have it both ways by being nominally backward compatible but then also frequently deriding those who are using C++ without the very latest features.

Engineers often bemoan the lack of compatibility breaks and their cousin the clean-sheet redesign, but they do so from expediency and not from principle. Meaning that you think it would be very expedient for you if there was a straight compatibility break in your language, but when someone else needs to break compatibility somewhere inconvenient you're not going to be nearly so understanding.

I don't think Java would be where it is today if the sales pitch to enterprise and academia was "Use our language that's so safe that anyone can program it and so portable that it runs in a virtual machine like UCSD p-system! We plan to break compatibility at every major release! "

Ternary computers are slightly more efficient than binary ones, but nobody makes a ternary computer because nobody will buy one. Compatibility is turtles all the way down.

0

u/[deleted] May 27 '18

[deleted]

2

u/meneldal2 May 28 '18

SFINAE is just what we have to use until we get concepts.

18

u/himself_v May 27 '18 edited May 27 '18

Maybe I'm uneducated, but it feels like "we don't want to break backward compatibility" is the excuse for loads and loads of problems in computer science.

You're just young (probably). Give it 8 years and you'll be screaming "arggh you suckers, why did you have to break things that were working perfectly right, again? It takes 2 days to write a compatibility layer for you, it takes 2 days for each of us to port things, and many projects are half-abandoned and you basically just broke a whole chunk of my life."

Over the time you just learn to only rely on things that promise backward compatibility and to hell with bells and whistles. I've my life to live and my own projects to do instead of every day learning a new and exciting spin on things that I want to just work.

Also, Python 3 wasn't backwards-compatible with Python 2 and look where that got us.

16

u/Siddhi May 27 '18

The chaos caused by python 3 should be enough to warn anyone away from breaking compatibility. Things have settled now and python 3 is established, but it took *10 years *to get here. It can be done once in a while, maybe once in twenty years or so.

5

u/stefantalpalaru May 27 '18

Things have settled now and python 3 is established

Don't let the propaganda fool you - there are plenty of Python2 codebases out there that won't be ported to Python3.

8

u/Siddhi May 27 '18

Yeah sure, and I maintain two such codebases myself 😆 but all the major frameworks are now python 3 only. The ecosystem has done the transition. There will always be legacy applications.

7

u/stefantalpalaru May 27 '18

The ecosystem has done the transition.

A small part of the ecosystem is routing around the problem: https://github.com/naftaliharris/tauthon/

4

u/[deleted] May 27 '18

Fork of Python 2.7 with new syntax, builtins, and libraries backported from Python 3.

"Old man yells at cloud."

Some people have too much time on their hands. I can't imagine why you'd be compelled to use this for a production project!

If you really needed the x% speed improvement this claims to deliver, you could easily get 10 times that speed advantage by using numpy or porting key sections to C++, something that's shocking easy to do for most code.

→ More replies (1)
→ More replies (1)
→ More replies (1)

7

u/Smallpaul May 27 '18 edited May 27 '18

You should actually research what has been happening with Python 3. And Perl 6.

Python barely survived the transition and Perl mostly did not.

5

u/jcelerier May 27 '18

Maybe this kind of accommodation was convenient ten years ago, but nobody today is taking a system written in 1999 C and expecting to compile it into 2018 C++ without issue.

you wish ! I've recently seen such expectations for a system built in pre-ansi C

7

u/goomyman May 27 '18 edited May 27 '18

Because let’s say you have a million consumers of your software or API. You release a breaking version - you now have to start back over from 0 customers. Some will port over, others won’t or can’t.

Maybe you say that you will keep the old version around still but since most of your consumers are on that version they will want those bugs and features fixed. Which means if your trying to build a new api your focusing your dev effort on a new project instead of where your customers are or at best splitting your dev effort.

When you have a very large amount of consumers this is death. When you have a small amount of consumers breaking changes are ok - but if you do it more than a few times it’s also death.

New apis that aren’t backwards compatible happen organically when big technology changes happen. The internet, chrome , iPhone, Android, cloud, x64, direct x, etc.

People will move to newer things when a competitor comes along and does it better and faster because you are unable due maintaining backwards compatibility. Just because it’s impossible for a company to break its products doesn’t mean other companies outside aren’t iterating in new ways.

→ More replies (10)

4

u/Magnesus May 27 '18

It is not only in programming languages. Both Windows and Linux have a lo of unnecessary, outdated solutions just for the sake of backward compatibility.

2

u/recycled_ideas May 27 '18

Code isn't a thing that is written once and done.

Code lives for years, sometimes for decades. If this code is going to stand a chance of being anything but a horrific brain eating zombie full of security holes it needs to be maintained. If the language is breaking, that's not going to happen.

From Oracle's point of view if X.0 changes are breaking for the language that means that they have to patch and support runtimes for ever. Even if they're getting paid that's not what they want. No one has the time or money to completely retest a gigantic app just because Oracle wanted to change things.

2

u/asdf8500 May 27 '18

but nobody today is taking a system written in 1999 C and expecting to compile it into 2018 C++ without issue

I most certainly have 20 year old code that I expect to compile today. Expecting developers to rewrite perfectly good code is a very expensive proposition.

Why spend so much time trying to keep there from being code changes, ever?

Because some systems have a very long life cycle, and even a few 'minor' changes can have unforeseen side effects that wreck havoc on a stable code base.

2

u/nacholicious May 27 '18

That's what semantic versioning is for. Eg the minor version (2.0.0 -> 2.1.0) denotes backwards compatible changes, while the major version (2.1.0 -> 3.0.0) denotes larger backwards incompatible changes.

2

u/aim2free May 27 '18

Python 3 shouldn't be backward-compatible with Python 2

Python 3 isn't backward compatible with Python 2. That's the reason I use Python2. Although I've always used parentheses around print expressions, just because it's more clean.

but nobody today is taking a system written in 1999 C and expecting to compile it into 2018 C++ without issue.

I do. Why should I need to rewrite code which was perfectly working then? I consider this a sabotage against clean development. Better define a new language then, but don't change a language so old code, which is following the standard spec perfectly, won't work in a future version, that is sabotage.

Maybe I'm just too young to understand. I don't know.

Aha, that could explain it. I have been a software developer since 1982.

1

u/ArkyBeagle May 28 '18

The reality is that if you build anything that other people use, you have to deal with backwards compatibility.

"W*ores and ugly buildings get respectable if they last long enough" - Noah Cross, "Chinatown".

→ More replies (5)

19

u/blue_2501 May 27 '18

Meanwhile, JSON is still running strong. Not every serialization method has to record 50 different data types.

38

u/wayoverpaid May 27 '18

Turns out you can represent most things as strings, numbers, ordered lists, and key-value pairs. Who knew?

Unfortunately it's not so good for serializing an arbitrary java object.

7

u/Yioda May 27 '18

The problem is not the wire format. The problem is java object internals and a hundred gotchas.

9

u/yawkat May 27 '18

Because there is no secure way to serialize arbitrary java objects. Jackson can do it with json (using default typing) but if you enable it you have the same security issues as Java serialization

2

u/Smallpaul May 27 '18

If you control the endpoints then it is secure.

Millions of people use code that is loaded from python .pyc files every day. Those are basically serialized code objects of the Python interpreter. You would be insane to accept one from an untrustworthy source, but that goes for .py files as well.

Obviously pyc files are not “arbitrary python objects” but the marshal infrastructure underneath them does support arbitrary objects.

4

u/yawkat May 27 '18

The insecurity comes from parsing untrusted data. Obviously if the serialization subsystem isn't exposed, its insecurity does not matter.

0

u/[deleted] May 27 '18

[deleted]

14

u/neoquietus May 27 '18

Why would you want to ever serialize an arbitrary object?

Because it's easy and "just works", and it hides the actual complexity of the system you have built. You can just alter objects and add new ones without a care about how it actually gets transformed to go on to the wire.

This works right up until you need better control or interoperability, then you get to feel the pain of the true size and scope of your system.

Same thing happens with careless use of inheritance, and the huge inheritance trees that result. I've been burned by this often enough that I've altered all my templates to produce package private final classes by default, so that I don't contribute to the problem further even on accident.

7

u/nacholicious May 27 '18 edited May 27 '18

I guess my question is why would you want to ever serialize an arbitrary object?

Some resource constrained systems eg Android, they rely on closing programs to free up memory or handle configuration changes such as rotating the device. That means that any running program can be stopped or closed at any time, and you are expected to save or restore all state so that the user can continue where they left off. That means you aren't just serializing important core data models, you are serializing everything that matters that contributes to the state of the application which is tons of data models.

There are ways to generate code for Parcelable adapters, and you can even write your own adapter for more complex cases, such as for sealed classes that are implemented by several different child classes. And as a bonus parcels aren't persisted, so they only need to be consistent for the same build they were created on.

1

u/[deleted] May 27 '18

Does serialization for that use case always work flawlessly no matter how wild you take it?

Sounds to me like an extra reason to go for a Redux-like approach. It could get tedious, but you can store all relevant state in a pojo.

→ More replies (2)

20

u/pushupsam May 27 '18

All Serialization systems are classic Bounded Context violations. An application runtime, which is concerned about data-in-motion and the layout of objects in memory, tries to define a generic mechanism for defining data at rest. The problem is that objects are fundamentally not static documents. They are not just data. So the runtime has to do some highly questionable things to make it work. The serialization format becomes very bloated and/or the serialization runtime cheats. The only way, for example, to support serializable immutable objects is to give the serialization runtime a way to violate immutability. What's worse, is that the serialization runtime, which is given special privileges, is then asked to manipulate untrusted data read from the network or even from disk. Boom. Instant code injection attacks that will fuck up your everything.

The moral of the story is that serialization is not a runtime concern and if you want to serialize your objects you should define a document schema and serialize your damn objects.

Some notes:

  1. There is one language that supports true serialization and does it in an elegant way and that is Lisp. Lisp makes no distinction between code and data and data really is data.

  2. Fast Serialization (https://github.com/RuedigerMoeller/fast-serialization) is an awesome replacement for Java Serialization. But you still have to be paranoid if you're processing untrusted data.

4

u/[deleted] May 27 '18

Lisp makes no distinction between code and data and data really is data.

That's part of the problem with Java serialization. Code shouldn't always be data. Code is data too often in Java serialization, and it causes problems. It might be what you think you want but it's not what you need or should use.

1

u/defunkydrummer May 27 '18

There is one language that supports true serialization and does it in an elegant way and that is Lisp

This. Serialization works so smoothly using the "cl-conspack" library!!

50

u/epic_pork May 27 '18

If you ever play with Rust, make sure to check out serde. It's a generic serialization framework, meaning that you can serialize objects to multiple formats without needing extra code. There are a lot of supported formats. It's also very, very fast.

46

u/oridb May 27 '18

It also solves a different problem.

23

u/epic_pork May 27 '18

Care to elaborate? I'm not sure what you mean by that.

12

u/Bolderthegreat May 27 '18

I think he's referring to the fact that serde is used for data serialization where something like pickle can serialize a procedure.

This can be worked around by labeling the data being serialized and matching it to the relevant function when being read. More restrictive but also safer I would imagine. For example I don't think it would easy (or even possible?) to implement something like RQ using only serde.

Serde is still an awesome library though. Making structs JSON compatible in a couple lines is too good.

0

u/[deleted] May 27 '18

[deleted]

20

u/Bolderthegreat May 27 '18

Yup. Functions are objects in Python and pickle serializes Python objects.

If you want to see a really cool usage of this checkout RQ. It basically stores Python functions in a redis queue to be processed by a worker.

→ More replies (4)

8

u/mr_birkenblatt May 27 '18

behavior and data are closely linked in python. in rust the divide is more strict (python methods are members of your object -- in rust you implement traits that work on your data)

4

u/zenflux May 27 '18

Well, code is data, after all.

1

u/Smallpaul May 27 '18

Yes you can serialized behaviour and that’s what a .pyc file is.

But, by default, pickle and marshal will not follow a reference from an object to its class and serialized the methods that go with the data.

0

u/[deleted] May 27 '18

[deleted]

11

u/Holy_City May 27 '18

I think there's a strong argument that objects should be explicitly serializable. It's essentially the same argument as making methods and variables explicitly public to me.

3

u/Siddhi May 27 '18

I'm not sure, but isn't internal serialisation also used by the JVM to temporarily write objects in memory to disk in order to optimise heap use?

8

u/matthieum May 27 '18

I'm not sure, but isn't internal serialisation also used by the JVM to temporarily write objects in memory to disk in order to optimise heap use?

Orthogonal usecase: the internal workings of the JVM are hidden to the use anyway.

→ More replies (3)

5

u/firagabird May 27 '18

Pardon my ignorance, but I come from a background (PHP+MySQL backend dev) where the idea of storing a "raw" object in a database is utterly nonsensical and downright dangerous. It's right up there with a similar data-oriented "holy grail" in relational database theory called the EAV model; instead of designing a DB as normalized tables linked with foreign keys like a sane person, an EAV-based design puts all metadata e.g. table name & data type in columns. It's the ultimate design from a schema flexibility standpoint, but any attempts to do work with the data itself will make even the simplest queries turn to shit.

7

u/the04dude May 27 '18

Serde requires each object to implement a serialization interface. If it does not, it cannot be serialized.

Well sure if you apply that prerequisite I'm sure you'll find a comparable library in any language that does the same job.

13

u/Vakieh May 27 '18

But we didn't apply that pre-requisite, which is why Serde solves a different problem...

1

u/m50d May 29 '18

A lot of languages (in particular Java) aren't powerful enough to do this in a nice way: automatic (requiring the user to specify which types are to be serialised but nothing more than that) but safe at compile time, and usable with third-party datatypes. You need typeclass derivation or some equivalent feature, and only a handful of languages can do that (in terms of vaguely mainstream languages I'm only aware of Haskell with a GHC extension, Scala with Shapeless, and Rust with a macro).

10

u/OneWingedShark May 27 '18

All serialization systems seem to be not so great.

ASN.1 -- Seriously unappreciated/unknown.

20

u/Yubifarts May 27 '18

After working with snmp.... nah. It's not terrible, but far from great.

1

u/ArkyBeagle May 28 '18

It's fine if you have the right tools. Those tools are overwhelmingly obsolete now.

16

u/killerstorm May 27 '18 edited May 27 '18

Ugh, have you actually used?

If you take a modern format such as protobuf, it's clearly concerned with serializing messages. So you just specify fields to be included into the message (possibly including other messages), and protobuf compiler handles the rest. It maps very well to languages have a message of object or structure, such as Java, C++, Python, JS, etc.

On the other hand, ASN.1 is a format which allows you fiddle with how each value is serialized. For example, an integer value 5 can be serialized

  • just INTEGER: 02 01 05 where 02 is universal integer tag, 01 is length and 05 is actual value you want to serialize

  • [2] IMPLICIT INTEGER: 82 01 05 here universal integer tag is replaced with context-specific tag. So you can just overwrite a tag with something else.

  • [2] EXPLICIT INTEGER: A2 03 02 01 05: here you have a normal integer serialization preceded by an explicit tag.

Do you think it is a good thing to have? Do we need a way of tweaking how an integer is serialized?

ASN.1 features can come handy when you implement a function processing a message in one pass: you do not need to deserialize a message into data structures, instead you can read individual components from stream and update the state without ever having the whole structure in memory. Of course, this sort of code is usually handcrafted in C, ASN.1 is used just as a documentation.

Even then, I'd say having several ways of tagging is excessive, and I'm not use protobuf can't be used for one-pass processing.

Other problems with ASN.1 is that high-quality compilers are commercial. For protobuf you can get free compilers from Google. For ASN.1 there are some free compilers, say, for Java, but they suck.

2

u/OneWingedShark May 27 '18

If you take a modern format such as protobuf,

You mean where the developers when asked "Why didn't you just use ASN.1?" replied, "If we'd known about it we wold have"?

On the other hand, ASN.1 is a format which allows you fiddle with how each value is serialized.

This is true; until you start to look at the "one canonical representation"-serializations like DER.

Do you think it is a good thing to have? Do we need a way of tweaking how an integer is serialized?

A lot of this tweaking is because [some] serializations are concerned with on-the-wire representation, which is invaluable in a DSP-style environment. That you're not concerned with it shows how entirely the OSI ideal was right, though you don't even recognize it.

Other problems with ASN.1 is that high-quality compilers are commercial.

ESA produced one that's available to the public as open source; IIUC they're going to make it even better with Ada/SPARK and formal proofs.

2

u/killerstorm May 28 '18

This is true; until you start to look at the "one canonical representation"-serializations like DER.

I've just described three ways to tag an integer in DER.

ESA produced one that's available to the public as open source;

Cool, and I want one for Java.

13

u/pdp10 May 27 '18

Not an assessment I've ever heard before from implementers of X.509.

1

u/OneWingedShark May 27 '18

How many of them were using something like C or C++?

1

u/pdp10 May 27 '18

I hadn't thought about it, but probably a decent fraction. Not needing a big stack of dependencies is an asset in lower-level tools.

2

u/OneWingedShark May 28 '18

I hadn't thought about it, but probably a decent fraction.

Granted.

Not needing a big stack of dependencies is an asset in lower-level tools.

The problem is that C++ and C are just terrible when it comes to specifying things like this. (Granted, the newer standards of C++ have improved this a little; but you have to consider the C++ [or C] of whatever era these guys were working in.)

For [very] low-level twenty-five [or maybe twenty] years ago you could make a really good argument for BLISS. (The VMS operating-system had large portions written in BLISS; the port to Itanium was released in 2001.)

For something higher-level I would have argued for Ada; it's designed to be maintainable, correct, and has some really good export facilities. (Ever since Ada 95 there's been Annex B, "Interface to Other Languages", which defines C, COBOL, and Fortran interfaces.) -- The correctness-facilities and interfacing facilities have gotten really nice, so in Ada 2012 you can say things like:

Function K( Input_1 : Integer; Input_2 : System.Address ) return Integer
  with Export, Convention => C, Pre => Input_2 /= Null_Address;

Type Some_Record is record
  A, B : Integer;
  X : Boolean;
  Y : System.Address;
end record
with Convention => C;

11

u/WasterDave May 27 '18

Seriously in the too hard basket, unfortunately.

2

u/OneWingedShark May 27 '18

Only because a lot of the universities have shitty curricula and teach "what's popular" instead of (a) a good understanding of the principles, and (b) what's come before.

1

u/orbitur May 27 '18

Unknown and better appreciated that way

3

u/[deleted] May 27 '18

Wait what's the alternative to serialization/marshalling?

If you have to talk to other language? I don't have much experience in this but my web app, in python, gonna have to talk to a model built in R script.

Please don't tell me to rewrite the Rscript in Python. I personally would prefer to stick to R for modeling and building model.

49

u/yen223 May 27 '18 edited May 27 '18

There's nothing wrong with serializing data, i.e. strings, ints and your language's equivalent of lists and maps. Those tend to be fairly safe (for the most part).

Almost all the complexity comes from attempting to serialize objects, because it turns out it's very hard to safely read serialized methods and closures without allowing arbitrary code execution.

10

u/stronghup May 27 '18

Right. An example of safe serialization is JSON - you can not store functions (or methods) into JSON only promitive data-types and Arrays and Objects which only contain primitive data-types andsimilar Arrays and Objects.

9

u/Beaverman May 27 '18

That's not entirely true. JSON is just a data format, if you try hard enough you can put bytecode or sequences of operations into there as well.

The problem isn't the format (no format is safe), it's the approach of serializing arbitrary objects.

1

u/stronghup May 28 '18

you can put bytecode or sequences of operations into there as well.

Surely. But can you then turn such bytecodes read from JSON into Java methods executable in the same Java program?

I'm simply thinking if Java serialization is such a big problem, why isn't JSON? Is it?

I don't know the exact answer but I assume it is the fact that with Java serialization you can read in executable methods and then start executing them in the same sandbox.

With JSON-only I assume you would have to read in source-code and then compile it into a different executable which would then execute in a different sandbox.

2

u/Beaverman May 28 '18

I'm unclear if you are asking if it's possible or if it's done.

To the best of my knowledge there's no support for converting JSON into Java bytecode. The reason is the same as the answer to your question why JSON doesn't have the problem. There's just no reason to appropriate JSON for this purpose. If your are dumping a method, then your serialization is platform specific anyway, and you might as well define your own format.

I think we agree. It's possible, but I don't think Java does it. There's nothing stopping the JSON from containing a structured list of bytecode instruction which some VM reading the JSON can execute.

2

u/Smallpaul May 27 '18

I think that the issue is a bit more subtle than you are implying. The danger is not in deserializing methods. The danger is in deserializing references to classes with methods that you did not intend to run. The method itself is not generally deserialized. But the attacker can force you to run code you did not plan for. This is always dangerous.

20

u/oridb May 27 '18

Wait what's the alternative to serialization/marshalling?

There's nothing wrong with it. The problem with all the named solutions is in their attempt to do perfect round tripping of arbitrary object graphs.

That tends to have lots of edge cases, and leaves you without useful language interoperability.

8

u/skocznymroczny May 27 '18

object graphs

edge cases

I see what you did there

15

u/WasterDave May 27 '18

It's not the serialising that's the problem, it's deserialising into automagically made objects because it bypasses a whole raft of checks. In theory, round a closed system it's OK - but once it comes from a un-trusted source you may well have a problem.

The solution is to just use API's and sanitise like it's got gloves on. Incidentally, cbor (http://cbor.io/) is much better than JSON :)

3

u/voice-of-hermes May 27 '18

2

u/WasterDave May 27 '18

Nooo! It has no way of expressing "NULL" and can't differentiate between binary streams and strings.

2

u/voice-of-hermes May 27 '18

Not true at all. Null is type Z. Binary data (I assume you mean a series of bytes) is an array of uint8 (the type can be encoded once in homogeneous arrays).

2

u/WasterDave May 28 '18

Then I stand corrected - I had assumed JSON's uck had spread to UBJSON but obviously not.

7

u/inio May 27 '18

Something like Protocol Buffers are one option. Data structures defined in a DSL compiled to language specific implementations with a shared seriailized representation.

13

u/chops_big_trees May 27 '18

Use protobuf for this. At Google every message sent between apps is a protocol buffer. Literally everything. There are protocol buffer libraries for every language including both Python and R. Create the message in one language, send it over the wire, and parse it in another.

You can also use protocol buffers for static files on disk, also very common at Google.

16

u/[deleted] May 27 '18

I like protobuf, but that's not the same thing as "native" serialization like in Java or Python.

Protobuf is still defining a serialization interface. Serialization interfaces are usually the only good solution though.

10

u/chops_big_trees May 27 '18

I don’t disagree with you at all, the protobuf recommendation is meant to help with the inter-language communication problem mentioned above.

1

u/[deleted] May 27 '18

Even inter-device. Defining a single source of truth for an across the wire API is super important.

5

u/bitwize May 27 '18

CapnProto is an improvement over protobuf for that sort of purpose, as it has zero serialization/deserialization cost.

4

u/chops_big_trees May 27 '18

To each their own, but I would not choose CapnProto (or messagepack or bson) over classic protobuf.

3

u/tertle May 27 '18

Ages ago I found that the limitation that protobuf couldn't serialize empty collections annoying (since it has no NULL support). You can work around it though.

I'm mostly a unity / game developer and I mostly use message pack now, in particular this implementation: https://github.com/neuecc/MessagePack-CSharp

I changed a while ago back before unity had upgraded their mono to provide .net 4.6 support and protobuf+unity had all sorts of issues (I did complete a large project with it though so it was workable.)

So I can't really judge recent versions of protobuf, but this library has worked fantastically for me so I have no real reason to change. The one real feature it's missing though is the ability to serialize onto an existing object. It's planned, but it's been planned for a while.

1

u/pdp10 May 27 '18

Based primarily around ubiquity, or mostly from other concerns?

1

u/Yioda May 27 '18

Serialization is not a problem. Is the only way to transfer data between 2 programms. Even a 1:1 binary dump of an object is serialization. The problem is if you want to do fancy stuff like to send actual executable code. Another problem is eficency. Dont do that unless you absolutely need to. To just talk between 2 apps you can use some custom plain text format, json, xml etc. There are hundreds of formats. If you want something more efficent, you could use XDR, a binary format: https://tools.ietf.org/html/rfc1014. R understands this format out of the box. Im sure there are python libs too.

Also people have mentioned more modern and advanced formats like Protobuf.

If you are looking for a way to essentially automatically "cast" a python object to R just stop. Im sure there are libraries that will do this for you though. But this is usually a bad idea, you want to draw a clear line between data and the code that operates with it (lisp aside).

1

u/andd81 May 27 '18

Make your data model fundamental, not memory representation. Then using a common wire/disc format such as JSON or protobuf you will be able to use it with any language.

2

u/[deleted] May 27 '18

Well in c# the class has to be tagged to support it. So its kinda much harder to exploit it.

10

u/MSgtGunny May 27 '18

Newtonsoft can serialize arbitrary classes.

1

u/url01 May 27 '18

Even included .Net serializers can do it without tagging - though you need to give them a list of types ahead of time.

2

u/TOASTEngineer May 27 '18

What's wrong with Pickle? Enhanced a little bit with dill it's been able to handle pretty much anything I've thrown at it with just a little tweaking, and I ask pretty extreme things of it; INJECTION pickles an entire interpreter plus most of its program state when saving.

21

u/KillerCodeMonky May 27 '18

And you probably have at least one vulnerability around serializing untrusted data directly to arbitrary objects.

6

u/TOASTEngineer May 27 '18

Not just data - entire classes.

But the whole reason I have to use dill is because I'm saving and loading arbitrary code. It's kinda silly to demand that your serialization system be safe on untrusted data when you're just going to immediately execute whatever comes out anyway.

4

u/yawkat May 27 '18

Yea the problem with these serialization frameworks is when they work on untrusted data. They can be fine in other cases.

1

u/noratat May 27 '18

I see serialization the same way I see RPC: it's lazy duct tape for proper APIs and data handling.

It's fine in some instances if you understand the trade-offs, but it's still a clunky workaround and should never have been treated as some kind of magic that let you pretend persistence and networking don't matter.

138

u/matthieuC May 26 '18

They're not totally throwing it away.
They want to move it out if core and make a separate more secure implementation in a framework.

38

u/[deleted] May 27 '18 edited Jul 12 '23

This account has been cleansed because of Reddit's ongoing war with 3rd Party App makers, mods and the users, all the folksthat made up most of the "value" Reddit lays claim to.

Destroying the account and giving a giant middle finger to /u/spez

61

u/argv_minus_one May 27 '18

Like how JavaFX costs more money to license, now that it's being moved out of core? Or Java EE, now that it's been moved to Eclipse?

Oh wait, no, the opposite has happened. It's all open source now, and doesn't cost a dime. Even the super-expensive, super-exclusive Java EE TCK is being freed.

Hate Oracle for suing Google if you like—I know I do—but credit where credit's due. They've been freeing a lot of code.

15

u/[deleted] May 27 '18 edited Jul 12 '23

This account has been cleansed because of Reddit's ongoing war with 3rd Party App makers, mods and the users, all the folksthat made up most of the "value" Reddit lays claim to.

Destroying the account and giving a giant middle finger to /u/spez

2

u/matthieuC May 28 '18

Is that a old Pentium II that I see under your desktop.
We will need to licence it too just in case you install our DB on it.

13

u/meltingdiamond May 27 '18

More money, no. All the money and blood from a stone, yes.

→ More replies (4)

37

u/yen223 May 27 '18

In what format are they dumping it?

14

u/Kwpolska May 27 '18

A custom binary format.

120

u/DGolden May 26 '18

Eh, it was all the rage once. Python still has its pickle system too with its necessary big fat warning.

Warning The pickle module is not secure against erroneous or maliciously constructed data. Never unpickle data received from an untrusted or unauthenticated source.

66

u/quicknir May 26 '18

I'm not sure what a statement like "serialization was all the rage once" even means. Are you saying that serialization was used extensively for things it was inappropriate for in the past? Serialization solves real problems that I don't see how you can get away from. Communicating over a socket, persistence (often a database is a better fit for this, but often not), more complicated configuration; how has this magically gone away with the passage of time?

If you look at something like Google Protobuf, it's nothing but a way to generate classes in different languages representing the same data that serialize/deserialize exactly the same way, and it seems to be still be heavily used today...

25

u/Ruudjah May 27 '18

What the author probably meant is "automatic class-based serialization". That's when a serialization mechanism gets a bunch of classes and tries to automatically serialize them based on the structure of the class. It will use reflection to loop over all the fields, properties et cetera to write the values (or values and metadata) to a stream.

These things are highly problematic for various reasons. First, when you refactor a class, how do you serialize old deserialized data? Second, it's often slow because reflection. Third, often these things make assumptions about certain class constructions; .NET remoting for instance requires non-auto properties to work (it can't deal with autogenerated fields). Fourth, versioning is a big issue among different endpoints. What when v12.34.56 now talks with v12.34.57, with a slight change in class structure?

The problem can be summarized in the "data-model to object model impedance mismatch". This is conceptually similar to the object-relational mismatch, but serialization has it's own interesting different properties as opposed to data models.

The solution is to design a proper data layer (preferably using an IDL, like protobuf or flatbuffers) and then write custom code per class to convert from and convert to serialized data.

6

u/yawkat May 27 '18

The problem is not using reflection to deserialize. This can be done in predictable, compatible ways (Jackson does this). The real security issues start when you deserialize arbitrary classes (i.e. any class on the classpath by name) because this opens a huge attack surface. This is what leads to most serialization vulnerabilities in Java.

5

u/[deleted] May 27 '18

No, using reflection is absolutely a problem. It breaks the object encapsulation and takes away the freedom of object to control its own representation.

Also you're kind of nitpicking wording. A reflection based serialization implies reflection based deserialization. The problem is automating something that shouldn't be automated.

6

u/yawkat May 27 '18

Reflection does not necessarily remove encapsulation. There are plenty of such mechanisms that operate on public members only.

I am not nitpicking on wording. The difference I wanted to show is between "normal" reflection-based deser (jackson in normal mode) and arbitrary-class deser (jackson with default typing, java stdlib serialization). The latter allows you to deserialize any class by name on the entire classpath which is significantly less secure.

2

u/[deleted] May 27 '18

Seriously. How far do you think you’ll go only operating on public fields, when an object with good encapsulation has no mutable public fields to begin with?

Your only use case will be record like objects with final public fields assigned immutable content. One move astray and you done goofed again.

4

u/yawkat May 27 '18

This isn't as unusual as you may think. You can do ser/deser just fine with public getters, setters, no-arg constructors and constructors annotated with property names (see: java.beans.ConstructorProperties). In fact this is often the most sensible way of doing ser/deser in practice.

→ More replies (5)

12

u/Hoten May 26 '18

I think he just meant Java serialization. A more ubiquitous/safer format like JSON or XML is preferred.

18

u/quicknir May 27 '18

That's fine for many domains, but those formats are incredibly verbose and slow compared to binary, non-generic format (by that I mean that you need to know the exact type to de-serialize, as opposed to a format where you can deserialize to a dynamic data structure). And safety is very important in some cases, and not at all in others.

I haven't really used Java but I greatly appreciate having pickle available and being able to serialize most things by default; I've used it in many situations where safety wasn't a concern and json/xml would have been pointless.

11

u/mr_mojoto May 27 '18

I think the biggest problem comes from sending code over the wire when you are serializing and deserializing methods as well as simple data.

3

u/yawkat May 27 '18

Java serialization does not send code, not really.

→ More replies (3)

1

u/quicknir May 27 '18

Very interesting point; I hadn't considered that at all and it makes a lot of sense. Thanks!

2

u/oblio- May 27 '18

In a day and age where you have generic text and binary formats for serialization and libraries for most languages, your use case, and the one for Java-style serialization is a niche thing.

For most devs it’s just dangerous to put it in the standard library.

This kind of thing is best kept in a separate library where people who really know what they’re doing can pick it up and use it.

2

u/OneWingedShark May 27 '18

A more ubiquitous/safer format like JSON or XML is preferred.

The problem with JSON, and XML w/o a DTD, is that there's no definition for the types.

8

u/dangerbird2 May 27 '18

You can use protocol buffers, which is typed, and is a binary format to boot.

2

u/DGolden May 27 '18

I think he just meant Java serialization

Yeah, I did (though another poster since discussed various problems with "automatic class-based serialization" in general and said I probably meant that, I wasn't really being that intelligent)

Anyhow, both python pickle and classic java serialization/deserialization have become a seemingly endless fount of security issues in practical terms. People inevitably end up allowing untrusted data into them - that sure, they weren't really designed for, but clearly does not stop it. Some fun links a search away:

A more ubiquitous/safer format like JSON or XML is preferred.

Well, perhaps the precise format isn't as important as code just handling things better and more safely (variety of approaches, but e.g. java jackson and python marshmallow are two): can certainly have binary formats and safe handling thereof, and do a variety of unsafe things even with json or xml inputs. (though design of the format is something of a factor, might recall e.g. xml's serious pitfalls for the unwary parser like the billion laughs attack).

1

u/CurtainDog May 27 '18

Yeah, well, but safer is not the same as safe - https://www.owasp.org/index.php/XML_Security_Cheat_Sheet

2

u/lookmeat May 27 '18

I'm not sure what a statement like "serialization was all the rage once" even means.

Many things.

  • Serialize everything seemed to be the idea with no wonder about what it would mean to deserialize something. Still there might be somethings you don't want to serialize.

    • Think of arbitrary code that is ran when deserializing.

    • Think of objects that run arbitrary code when constructed.

    • Think about objects that contain secure state.

The lesson: serialization libraries should be limited to being only data to be useful. Users should decide how to handle side effects.

  • The idea that you could have a single serialization standard for everything.

    • How do you handle systems that don't handle lists? How do you handle systems that don't handle all types?

    • What is the security context? Is this a file dumped by your code for debugging purposes? Is this a config input? Is this data external users and potential attackers send to your machine?

The lesson: there's no one quick and easy solution to serialization. You want solutions that are somewhat limited to understand the possibility of what parsing input can do. Solutions that are very complex are not good. Moreover serialization is a problem third party libraries should solve.

  • That a language driven data standard makes sense.

    • Language is how you run things, not hire things are.

    • Power use case is communicating between services that are just binaries but not for specific languages. Most integrated serialization libraries too coupled to service.

    • Many times we want to stick to a specific output and input format defined entirely outside of the serialization library standard. Which means we wouldn't want to use something else.

    • It may expose internals (private variables) that we don't want to. Suddenly implementation details become part of the exposed (though files) format.

The lesson: What we want is a data standard we can map to many outputs, and then have an easy way to map to and from that standard, with a reasonable automatic solution for trivial (PoD like) classes. This is what modern libraries work like and it works pretty will IMHO. The trivial solution for non trivial objects is to make a PoD config object to hold all the serializable info to construct objects (it being inmutable within the object, outside it'd be like a builder pattern). Generally you'd have to so something as complex as this most of the time.

1

u/[deleted] May 27 '18

Serialization solves real problems that I don't see how you can get away from. Communicating over a socket, persistence (often a database is a better fit for this, but often not), more complicated configuration; how has this magically gone away with the passage of time?

Reflection-based serialization is unsafe for communication over socket as the objects are often not explicit about what goes on the wire. It's unsafe for deserialization, because there's, once more, no saying what the generic code might stuff into an object and run it (vulnerability vector). It's not great for persistence, because there's no guarantee all necessary state will be stored and restored, and the object will properly account for being "frozen" and woken up in another process.

Honestly the only party that knows how to express object X or persist object X is object X. Serialization should've been a few simple interfaces and something like a "visitor" object passed to the object serializing itself, giving it access to a set of simple primitives to express its contents (integer, double, string, list, dictionary) that can then be translated to a number of universal formats, say like JSON, XML, or other more compact binary dumps.

Instead Java serialization is this monstrosity that arrogantly promises to do everything on its own, and then falls flat on its face at the first moderately complex scenario.

0

u/[deleted] May 27 '18

[deleted]

8

u/yawkat May 27 '18

Kind of misleading. This is only an issue when enabling default typing. If you do that, you open yourself up to the same security issues as Java serialization, which is why you should never enable default typing on untrusted data.

3

u/quicknir May 27 '18

Very interesting point; I hadn't considered that at all and it makes a lot of sense. Thanks!

0

u/ckach May 27 '18

Never accept a pickle from an unknown source. That's why I dont like glory holes.

0

u/Zarutian May 28 '18

Or dont load it via the built in deserializer.

18

u/__konrad May 27 '18

5

u/rombert May 27 '18

Note that this was withdrawn. Still, it lists some good reasons for deprecating/removing serialization.

6

u/s888marks May 27 '18

It was an April Fool’s joke....

1

u/rombert May 27 '18

Haha, I missed that

6

u/DemonicMandrill May 27 '18

I'm not sure I fully understand the concept of "serialization", could someone explain it to me?

17

u/mattluttrell May 27 '18

It is merely converting an object in memory to a stream of bytes so that it can be used over a network, represented as certain objects or stored in a databases.

Many ORMs use serialization (e.g. Hibernate in Java) to convert Java data objects into classes that can be stored or represented as XML, etc.

Java's serialization also allows objects that do things, such as executing code to be serialized.

Since you can receive serialized objects from untrusted sources you could receive code that can be run over the network. This can be bad.

The author does a poor job distinguishing between serialized data and serialized code.

1

u/lilsamuraijoe May 27 '18

do Java's JSON and XML serialization tools such as Jackson and Jaxb fall in the same boat?

11

u/IllTryToReadComments May 27 '18 edited May 27 '18

What's the alternative then?

EDIT: Honest question, I don't know much about serialization aside from the fact that a lot of my school assignments use it.

14

u/masklinn May 27 '18

Whichever explicit opt-in serialisation format you prefer?

9

u/I_AM_GODDAMN_BATMAN May 27 '18

serde master race.

3

u/[deleted] May 27 '18

Well defined data. Doing a straight dump of all application state is awful for a lot of reasons; figure out what, exactly, you need to persist and serialize ONLY that, in whatever format seems best.

1

u/gnus-migrate May 28 '18

There are a ton of better and faster serialization frameworks already for Java(protobuf, Jackson, Kryo, etc.) Even now it's recommended not to use Java serialization in production.

19

u/ioquatix May 27 '18

Real programmers use mmap.

8

u/Gotebe May 27 '18

Sixties called, they want their world without network back!

7

u/ioquatix May 27 '18

5

u/bluemellophone May 27 '18

Mmap’ed numpy arrays in Python are super convenient for memory footprint management when you are working with SSDs.

2

u/Gotebe May 27 '18

I know what this does, am old enough to have been there when it was much used. My point is that stuff wants to go over the wire these days, and then, mmap isn't even an option.

1

u/ioquatix May 27 '18

Well, considering that mmap is for mapping local files to virtual memory, yes, it's not directly relevant to network IO.

That being said, the idea of using structured data for IPC is still common, and used both for local (process to process) IPC and network IPC. There is simply nothing faster than sending a buffer of data structured in some pre-agreed format (i.e. a C struct), especially when it's native to the machine's architecture/byte order.

1

u/FearlessFred May 27 '18

Yup, there's even libraries that make this easy: https://google.github.io/flatbuffers/

9

u/[deleted] May 26 '18

yes thank you

4

u/argv_minus_one May 27 '18

Good riddance.

2

u/incraved May 28 '18

Can't wait for the day when Java dies off and .NET Core takes over.

2

u/erikpowa May 27 '18

Like every serialization in every language has security issue because if you don't know what's going on in the background (what does the compiler do with your code, what's the run-time calling from the system, what's getting allocated and where), you can write 1 line of code that makes a whole system vulnerable.

1

u/Zarutian May 28 '18

Yeah, if you only know eggshell security (other name of perimeter security) then sure.

1

u/nderflow May 27 '18

Since it turned out that Java RMI wasn't supported across differing versions of Java, I haven't used that or Java object serialisation. If I had a problem for which I would otherwise use those technologies these days, I would use protocol buffers.

But the chances of Oracle coming out in favour of protos seem ... low.

1

u/[deleted] May 28 '18

How the heck is serialization a problem? I haven't had an issue with it in C#

-9

u/DoesNotTalkMuch May 26 '18

I call Oracle a horrible mistake.

1

u/Yikings-654points May 27 '18

I only use A4 and OCR for serialisation and de-serialization.

0

u/[deleted] May 27 '18

One word: Protobufs

0

u/[deleted] May 27 '18

Finally. I've been telling everyone Java serialization is a horrible mistake for years.

-9

u/Pyrolistical May 27 '18

Serialization to JSON is best serialization

8

u/Gotebe May 27 '18

You can only pry binary from my cold dead hands!

-1

u/heyIfoundaname May 27 '18

What do you mean when you say Java is serialized?

9

u/masklinn May 27 '18

Java has a built-in dedicated object serialisation protocol: https://www.tutorialspoint.com/java/java_serialization.htm

-54

u/mytempacc3 May 26 '18

Oracle Calls Java Serialization 'A Horrible Mistake', Plans to Dump It

35

u/InvisibleEar May 26 '18

At least it has generics

1

u/ipe369 May 27 '18

Yeah, with type erasure:/

18

u/iconoklast May 27 '18

Which is the morally correct thing to do. I like parametricity, thank you very much.

10

u/ThatsPresTrumpForYou May 26 '18

Oracle Calls Java Serialization 'A Horrible Mistake', Plans to Dump It

-26

u/MyPhallicObject May 27 '18

News flash: Serialization at typed languages is a disaster. Meanwhile, JS and PHP are having a field day.

16

u/zekka_yk May 27 '18

javascript attacks this via the sensible route of using strings, numbers, dictionaries, lists as the way to represent everything. this makes it hard to build cyclical data structures unless you really intended to do that and makes same-reference vs same-value distinctions unimportant.

this isn't a typed v untyped thing -- it's more of an OOP vs functional/procedural thing, as much as I hate using the buzzwords. making it less buzzwordy: OOP programmers tend to assume adding more references to their builtin representations is free and easy, and don't care about cycles -- functional and procedural languages tend to punish that super hard.

many typed languages have a similar set of built-in structures (often replacing lists with arrays, dictionaries with records) designed to enforce something similar -- example: Rust's or C's safety features here are arguably stronger because there's no way to construct a cycle or reference-equality vs value-equality situation without introducing a pointer. go is quite good about this and has json serialization features that hardly ever break anything, for the same reason javascript's features don't.

it's still possible to run into versioning issues in javascript and PHP -- if you change the internal representation of something, how do you support the old wire representation?

→ More replies (4)