(#1404) Contain reference and field failures in Kryo 4 #1405
These helpers are only used by the base FieldSerializer loops, but VersionFieldSerializer, TaggedFieldSerializer, and CompatibleFieldSerializer override read/write and invoke CachedField.read/write directly (for example, CompatibleFieldSerializer.java:65 and :145). Consequently the same exception or OutOfMemoryError still escapes raw when any of those public field serializers is used, so the containment is incomplete. Make the wrapper dispatch available to subclasses and use it in their loops, or centralize the cached-field calls before considering this fix complete.
<!-- ccr-overview-v2 -->
Copilot review overview
🟡 Changes recommended
Field serializer subclasses bypass the new wrappers, and reference tests do not enable references, leaving containment and coverage incomplete.
Review effort: Lite
Findings: 1 <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture>
<details open>
<summary><strong>Open (1)</strong></summary>
</details>
<details>
<summary><strong>What changed in this PR</strong></summary>
This PR adds Kryo 4 exception containment for invalid references and cached-field failures while preserving causes and valid serialization behavior.
Changes:
KryoExceptions.| File | Summary |
|---|---|
| test/com/esotericsoftware/kryo/FailureContainmentTest.java | Adds reference, field failure, and compatibility tests. |
| src/com/esotericsoftware/kryo/serializers/FieldSerializer.java | Adds contextual field-operation failure wrapping. |
| src/com/esotericsoftware/kryo/Kryo.java | Contains reference lookup failures with context. |
</details>
---
💡 <a href="/EsotericSoftware/kryo/new/kryo-4?filename=.github/skills/code-review/SKILL.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add a code-review agent skill</a> or configure MCP servers for context-aware, tailored reviews. <a href="https://docs.github.com/copilot/how-tos/use-copilot-agents/request-a-code-review/use-code-review?tool=webui#mcp-servers-and-agent-skills" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn more in the docs.</a>
Hi @vjanelle. I'm not a big fan of releasing Kryo 4, but I have done it once already for an important fix. Can you tell me why you want that change? Because some code scanner complains or because this is a real problem?
@theigl this is the main thing I think the advisories are complaining about / the fuzzers are tripping up on.
@theigl Sonatype-2021-1215 and Sonatype-2021-1216 are about uncaught exceptions (same as what was patched in kryo 5), which could lead to crashing bugs. As for "important", this is not something we currently experience but a potential thing. Sonatype is taking the google ossfuzz reports(I think) and generating their own internal advisories which we then have to make decisions on. The advisories are private, but basically they just say that an exception that handles when Kryo is serialising code would not be caught, and that'll end up terminating the JVM.
Unfortunately the DoD with FedRAMP is changing their rules come December and a lot of potential issues are getting escalated up. I can't honestly justify this beyond a potential crash bug, but "in the age of AI we can't just assume things" anymore.
Sorry. >.< Only thing I can do is ask nicely, but I'll try to be following up with the apache spark project to see if we can excise/vendor com.twitter:chill, and/or update to kryo5.
If it'll help, I can create an issue first in the spark jira about updating kryo. I do have to support spark 3.5 for a while though (which has an extended long term release from the apache spark project), so that would have to go into 4.x.
Sonatype-2021-1215 and Sonatype-2021-1216 are about uncaught exceptions (same as what was patched in kryo 5), which could lead to crashing bugs. As for "important", this is not something we currently experience but a potential thing. Sonatype is taking the google ossfuzz reports(I think) and generating their own internal advisories which we then have to make decisions on. The advisories are private, but basically they just say that an exception that handles when Kryo is serialising code would not be caught, and that'll end up terminating the JVM.
Unfortunately the DoD with FedRAMP is changing their rules come December and a lot of potential issues are getting escalated up. I can't honestly justify this beyond a potential crash bug, but "in the age of AI we can't just assume things" anymore.
OK i understand. Are these the only 2 advisories about Kryo 4 or are there more?
Sorry. >.< Only thing I can do is ask nicely, but I'll try to be following up with the apache spark project to see if we can excise/vendor com.twitter:chill, and/or update to kryo5.
If it'll help, I can create an issue first in the spark jira about updating kryo. I do have to support spark 3.5 for a while though (which has an extended long term release from the apache spark project), so that would have to go into 4.x
That would definitely be the way to go. Kryo 4 is more than 8 years old by now. If i remember correctly there were several efforts to upgrade chill to 5 and multiple PRs in that direction, but I'm not sure what happened to them.
I'm currently working on Kryo 6 and I need to do a Kryo 5 release this week. I can't promise anything, but I'll try to look into this.
@vjanelle: Can you take a look at this please?
@theigl appreciated.
Those are the only two advisories about kryo 4 as far as I can tell. I can share the text with you privately if you don't mind me emailing you, it's nothing exciting however.
@theigl oh, with regards to chill; I suspect it's abandoned now with the recent change in company ownership.
@theigl this will involve adding bounds checking (which was done to kryo5), will seperate that into its own commit.
vjanelle
Malformed object references and allocation failures during cached-field operations can escape Kryo 4 as raw exceptions or errors. This change converts those failures to
KryoExceptionwhile retaining their causes and adding reference or field context.OutOfMemoryErrorfrom ordinary and serialized transient field reads/writes with the field name, operation, and input/output position.KryoExceptioninstances unchanged and preserve existing read cleanup.This addresses the demonstrated paths associated with Sonatype-2021-1215 and Sonatype-2021-1216. Public APIs, registration behavior, and valid serialized bytes are preserved. This provides exception containment; protection against general memory exhaustion and Sonatype recognition of a patched artifact require separate work.
The related 5.x history, including the later revert of allocation-error wrapping, is documented in #1404. Kryo 4 remains relevant to downstream users of com.twitter:chill and Apache Spark.
Validation:
Closes #1404.