You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by "rzo1 (via GitHub)" <gi...@apache.org> on 2026/07/17 16:27:09 UTC

[PR] [2.x] OPENNLP-1891: Harden Deserialization in BaseModel (opennlp)

rzo1 opened a new pull request, #1186:
URL: https://github.com/apache/opennlp/pull/1186

   Backport of #1185 to the `opennlp-2.x` branch.
   
   Adds a filtered `BaseModel.deserialize(Class, InputStream)` helper that installs an `ObjectInputFilter` allowlist on the stream before the first object is read - the only point at which the top-level object can be protected, since a filter cannot be installed from within `readObject`.
   
   Changes relative to #1185:
   - Paths adapted to the 2.x module layout (`opennlp-tools` instead of `opennlp-core/opennlp-runtime`).
   - Javadoc reference to `SvmDoccatModel` removed, as that class does not exist on 2.x.
   
   Verified with `mvn -pl opennlp-tools clean test -Dtest=BaseModelTest` (2/2 pass, checkstyle/forbiddenapis clean).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opennlp.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [2.x] OPENNLP-1891: Harden Deserialization in BaseModel (opennlp)

Posted by "mawiesne (via GitHub)" <gi...@apache.org>.
mawiesne merged PR #1186:
URL: https://github.com/apache/opennlp/pull/1186


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opennlp.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [2.x] OPENNLP-1891: Harden Deserialization in BaseModel (opennlp)

Posted by "mawiesne (via GitHub)" <gi...@apache.org>.
mawiesne commented on code in PR #1186:
URL: https://github.com/apache/opennlp/pull/1186#discussion_r3607472073


##########
opennlp-tools/src/main/java/opennlp/tools/util/model/BaseModel.java:
##########
@@ -685,9 +686,46 @@ private void writeObject(ObjectOutputStream out) throws IOException {
     this.serialize(out);
   }
 
+  /**
+   * Allowlist for classes that may legitimately appear while deserializing a
+   * {@link BaseModel} via the standard {@link Serializable} mechanism.
+   */
+  private static final ObjectInputFilter DESERIALIZE_FILTER = ObjectInputFilter.Config.createFilter(

Review Comment:
   See comment in #1185



##########
opennlp-tools/src/test/java/opennlp/tools/util/model/BaseModelTest.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package opennlp.tools.util.model;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InvalidClassException;
+import java.io.ObjectOutputStream;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import opennlp.tools.chunker.ChunkerModel;
+
+/**
+ * Tests {@link BaseModel#deserialize(Class, java.io.InputStream)} and the
+ * {@link java.io.ObjectInputFilter} it installs.
+ */
+public class BaseModelTest {
+
+  @Test
+  void testDeserializeRoundTrip() throws Exception {
+    ChunkerModel model = new ChunkerModel(
+        this.getClass().getResourceAsStream("/opennlp/tools/chunker/chunker170default.bin"));

Review Comment:
   See comment in #1185



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opennlp.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org