Serialize ObjectArrayMessage elements through the filtered wrapper - #4274
Open
ppkarwasz wants to merge 1 commit into
Open
Serialize ObjectArrayMessage elements through the filtered wrapper#4274ppkarwasz wants to merge 1 commit into
ObjectArrayMessage elements through the filtered wrapper#4274ppkarwasz wants to merge 1 commit into
Conversation
`ObjectArrayMessage.readObject` read its `Object[]` with a plain `readObject()` call, the last remaining direct object read in a shipped `readObject` method. It now uses the same per-element `writeWrappedObject`/`readWrappedObject` mechanism as `ParameterizedMessage`, which re-applies the deserialization allowlist to each element and replaces non-`Serializable` elements with their `String.valueOf` representation on the writing side. The shared loop moves to `SerializationUtil.writeWrappedObjects`/ `readWrappedObjects`, which also bounds the array allocation during deserialization: at most 256 elements are pre-allocated and the array grows as elements are actually read, so a forged length cannot force a large allocation. `ParameterizedMessage`, whose serialized form is unchanged, picks up the same bound on its previously eager `new Object[argCount]`. Compatibility: the serialized form of `ObjectArrayMessage` changes; streams written by earlier versions are rejected by newer readers and vice versa. Part of the hardening series from #4168. Assisted-By: Claude Fable 5 <noreply@anthropic.com>
ppkarwasz
force-pushed
the
feat/2.x/object-array-message-wrapped
branch
from
August 31, 2026 21:57
3e4c620 to
0de250f
Compare
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Important
This PR is part of the deserialization hardening work tracked in #4168. The Logging Services PMC does not use nor recommend Java serialization/deserialization, and our security FAQ has long documented this position. This work is submitted solely to reduce the false-positive "vulnerability" reports that keep being filed regardless of that FAQ. Its utility for end users is close to zero.
ObjectArrayMessage.readObjectread itsObject[]with a plainreadObject()call — the last remaining direct object read in a shippedreadObjectmethod. It now uses the same per-elementwriteWrappedObject/readWrappedObjectmechanism asParameterizedMessage, which re-applies the deserialization allowlist to each element inside its own nested stream, degrades a rejected or unreadable element tonullinstead of losing the whole array, and replaces non-Serializableelements with theirString.valueOfrepresentation on the writing side.A single wrapped blob of the whole array (the literal
ObjectMessageshape) was considered and rejected: theObject[]would then be allocated inside the JDK's nested stream, where a forged array header still forces an unbounded eager allocation, and the resultingOutOfMemoryErrorescapesreadWrappedObject'scatch (Exception | LinkageError).The shared loop moves to
SerializationUtil.writeWrappedObjects/readWrappedObjects, which also bounds the allocation during deserialization: at most 256 elements are pre-allocated and the array grows as elements are actually read, so a forged length fails on the missing data instead of committing the reader to a large allocation.ParameterizedMessage— whose serialized form is byte-for-byte unchanged — picks up the same bound on its previously eagernew Object[argCount].Compatibility: the serialized form of
ObjectArrayMessagechanges; streams written by earlier versions are rejected by newer readers and vice versa.ParameterizedMessageandObjectMessageare unaffected.Stacked on #4272.