garydgregory commented on code in PR #746:
URL: https://github.com/apache/commons-text/pull/746#discussion_r3340553244


##########
src/test/java/org/apache/commons/text/TextStringBuilderClearTest.java:
##########
@@ -0,0 +1,191 @@
+/*
+ * 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
+ *
+ *      https://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 org.apache.commons.text;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.Reader;
+import java.nio.charset.StandardCharsets;
+
+import org.apache.commons.lang3.CharUtils;
+import org.apache.commons.lang3.SerializationUtils;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests that {@link TextStringBuilder} shrink and clear paths do not leave 
stale chars in the backing buffer.
+ * <p>
+ * readFrom(Reader) reads directly into the internal char[] buffer, so a 
Reader that is also an attacker can observe stale chars in that buffer beyond 
the
+ * logical content. The buffer is non-transient, so stale chars also survive 
serialization.
+ * </p>
+ * <p>
+ * Post-patch: clear(), delete(), replace() and setLength() NUL out the freed 
region so stale chars are not exposed.
+ * </p>
+ */
+public class TextStringBuilderClearTest {
+
+    /**
+     * A Reader that, upon reading, inspects the char array it has been given 
access to (positions beyond offset+len that may contain stale data), records 
them,
+     * then supplies its normal data.
+     */
+    static class SpyReader extends Reader {

Review Comment:
   In the future, reduce the copy pasta please, you've already added this class 
in a previous PR.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to