OPENNLP-1823: Harden SvmDoccatModel.deserialize() with ObjectInputFilter and resource limits#1029
Merged
Conversation
…ter and resource limits Apply a JEP 290 ObjectInputFilter to SvmDoccatModel.deserialize() that allow-lists only the classes reachable from a legitimate model graph and bounds graph depth, references, and array length. Foreign payloads are now rejected with InvalidClassException before readObject() returns, rather than after the cast. Add a public DeserializationLimits record and a deserialize(InputStream, DeserializationLimits) overload so callers with unusually large models can raise the resource limits without touching the class allow-list. The original deserialize(InputStream) signature is preserved and now delegates to DeserializationLimits.DEFAULT.
subbudvk
reviewed
May 2, 2026
…larify allow-list comment Validate stream and limits arguments to SvmDoccatModel.serialize() and SvmDoccatModel.deserialize() up front and throw IllegalArgumentException for null inputs instead of letting a NullPointerException surface from inside the JDK stream constructors. Document the contract on each method's Javadoc. Update the comment on the JDK section of the deserialization filter allow-list to explain why the abstract supertypes java.lang.Number and java.lang.Enum must remain on the list — ObjectInputStream invokes the filter for every class descriptor in the inheritance chain, not only for the runtime class.
Contributor
|
Looks good. Thanks! |
mawiesne
approved these changes
May 2, 2026
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.
Apply a JEP 290 ObjectInputFilter to SvmDoccatModel.deserialize() that allow-lists only the classes reachable from a legitimate model graph and bounds graph depth, references, and array length. Foreign payloads are now rejected with InvalidClassException before readObject() returns, rather than after the cast.
Add a public DeserializationLimits record and a deserialize(InputStream, DeserializationLimits) overload so callers with unusually large models can raise the resource limits without touching the class allow-list. The original deserialize(InputStream) signature is preserved and now delegates to DeserializationLimits.DEFAULT.
FYI @subbudvk Please have a look.