Commit e430766
committed
GROOVY-12268: Resolve deserialized class names without initializing them
The class-loader-aware newObjectInputStream overrode resolveClass with
Class.forName(desc.getName(), true, classLoader)
where ObjectInputStream's own resolveClass passes false. Pass false too.
History: the override was written in af544cb (2008-12-05) for GROOVY-1627,
"Deserialization fails to work", and has never been changed since; the 2012
extraction of IOGroovyMethods out of DefaultGroovyMethods (f0ca689) only
moved it. The initialize flag looks incidental rather than chosen. The same
2008 commit added newObjectInputStream(InputStream) with no override at all,
which therefore defers initialization the way the JDK does, so the two
siblings disagreed from the day they were written; and the problem being
solved was which loader can see a script-defined class, not whether that
class should be initialized. The accompanying test, StreamClassloaderInScriptTest,
passes either way.
Effect: a class named in a stream that then fails to deserialize no longer
has its static initializer run. The window is narrow but reachable by anyone
who controls the stream, since resolveClass runs before the local class
descriptor is looked up: a stream truncated between those two points
initializes the named class under true and does not under false. Once the
local descriptor is looked up the class may initialize regardless, because
reading a declared serialVersionUID field initializes it, and a stream that
deserializes successfully initializes the class when the instance is
created. No legitimate stream can observe the difference.
No test accompanies this. Reaching the window requires failing between
resolveClass and the descriptor lookup, which is only expressible as a
byte-offset truncation of a serialized stream and would be brittle; an
attempt using a serialVersionUID mismatch to fail deterministically was
discarded because reading that field initializes the class by itself and so
cannot distinguish the two settings.1 parent e3f320e commit e430766
1 file changed
Lines changed: 5 additions & 2 deletions
Lines changed: 5 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
270 | 270 | | |
271 | 271 | | |
272 | 272 | | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
273 | 277 | | |
274 | 278 | | |
275 | 279 | | |
| |||
281 | 285 | | |
282 | 286 | | |
283 | 287 | | |
284 | | - | |
285 | | - | |
| 288 | + | |
286 | 289 | | |
287 | 290 | | |
288 | 291 | | |
| |||
0 commit comments