Skip to content

OPENNLP-1823: Harden SvmDoccatModel.deserialize() with ObjectInputFilter and resource limits#1029

Merged
rzo1 merged 3 commits into
mainfrom
OPENNLP-1823
May 2, 2026
Merged

OPENNLP-1823: Harden SvmDoccatModel.deserialize() with ObjectInputFilter and resource limits#1029
rzo1 merged 3 commits into
mainfrom
OPENNLP-1823

Conversation

@rzo1
Copy link
Copy Markdown
Contributor

@rzo1 rzo1 commented May 2, 2026

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.

@rzo1 rzo1 requested review from atarora, jzonthemtn and mawiesne May 2, 2026 08:53
@rzo1 rzo1 self-assigned this May 2, 2026
…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.
rzo1 added 2 commits May 2, 2026 11:39
…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.
@subbudvk
Copy link
Copy Markdown
Contributor

subbudvk commented May 2, 2026

Looks good. Thanks!

@rzo1 rzo1 merged commit 3cf42d4 into main May 2, 2026
9 checks passed
@rzo1 rzo1 deleted the OPENNLP-1823 branch May 2, 2026 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants